Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8274321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:42:03+00:00 2026-06-08T07:42:03+00:00

I have a template class NB::B<T> derived from a non-template class NA::A in a

  • 0

I have a template class NB::B<T> derived from a non-template class NA::A in a namespace. act<T> is a template function calling add_ref function on an instance of its template argument. Specifically, act<NB::B<int>> wants to find add_ref defined in the namespace of NB::B‘s base using ADL. The complete example is following:

template<class T>
void act() {
  T* p = 0;
  add_ref(p); // the failing line
}

namespace NA
{
  struct A { };

  // I want ADL to find this:
  void add_ref(A* p) {
  }
}

namespace NB
{
  // template class with non-template base
  template <class T>
  struct B: NA::A { };

  typedef B<int> Bi;

  // using NA::add_ref; // fixes the problem
}

int main()
{
  act<NB::Bi>();
}

This compiles okay in gcc (4.7.0). And in Comeau online. However clang (3.1) fails:

a.cpp:4:3: error: use of undeclared identifier 'add_ref'

At the same time, the standard reads:

3.4.2/2 …

— If T is a template-id, its associated namespaces and classes are the namespace in which the template is defined; for member templates, the member template’s class; the namespaces and classes associated with the types of the template arguments provided for template type parameters (excluding template template parameters); the namespaces in which any template template arguments are defined; and the classes in which any member templates used as template template arguments are defined.

Surprisingly, template’s bases aren’t listed as paths to associated namespaces. Thus clang‘s behavior appears to be correct. And Comeau and gcc are accepting incorrect program.

At the same time, 3.4.2/3 states that using‘s in argument’s namespaces have no effect:

When considering an associated namespace, the lookup is the same as the lookup performed when the associated namespace is used as a qualifier (3.4.3.2) except that:

— Any using-directives in the associated namespace are ignored.

But when I uncomment the using NA::add_ref line clang is happy to compile the test.

To put my example into practical perspective, you can think that act was a method of boost::intrusive_ptr, add_ref(A*) was intrusive_ptr_add_ref(CBase*) and B was some template, deriving from base CBase.

Regarding this I have several questions:

  1. Am I right that clang‘s is correct rejecting my test program, and gcc and Comeau don’t follow the standard?

  2. Is there a reason why the standard specifies such an impractical behavior (disallows template class bases as associated namespaces)?

  3. Is clang wrong accepting my test program with the using NA::add_ref directive on the grounds of 3.4.2/3?

  4. Should I report a bug? 🙂

P.S. I have read clang Language Compatibility FAQ and didn’t find an answer there.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T07:42:04+00:00Added an answer on June 8, 2026 at 7:42 am

    From n3337, which is basically C++11 with minor editorial changes, the 3.4.2/2 reads:

    For each argument type T in the function call […] The sets of
    namespaces and classes are determined in the following way: […]

    • If T is a class type (including unions), its associated classes are: the class itself; the class of which it is a member, if any; and its direct and indirect base classes. Its associated namespaces are the namespaces of which its associated classes are members. Furthermore, if T is a class template specialization, …

    And it then continues with basically the same quote you posted in the question. The important difference here is the furthermore, which means that the list that you quoted (and I omitted) is in addition to the already mentioned namespaces, and that includes the namespaces of which the base class is a member.

    1. Gcc and comeau are right, and clang++ is wrong in rejecting the code.

    2. < does not apply >

    3. Clang++ is wrong in rejecting it without the using NA::add_ref.

    4. Yes, you should probably report a bug. It seems that it has already been reported and fixed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class derived from slider which uses a custom control template and
I have non-template class with a templatized constructor. This code compiles for me. But
I have a template class with a variadic template member function that I am
I have the following contrived example (coming from real code): template <class T> class
More specifically, let's say I have a class template with parameters A and B
More specifically, let's say I have a class template with parameters A and B
I'm having a problem in C++ with calling a function of a derived class
I have the following template class and a (global) variable of its type: template
I have a SDI MFC application which CMainFrame class is derived from CFrameWndEx. The
I have a class Base in base.h , which has a template function class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.