Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error C2327: not a type name, static, or enumerator

I am facing "error C2327" on windows.
I reduced my code and get similar error with test program

#include <boost/intrusive/list.hpp>
#include <iostream>

class Test {
protected:
         typedef Test self_type;
         boost::intrusive::list_member_hook<> order_hook;
public:
         typedef boost::intrusive::member_hook<self_type,
                            boost::intrusive::list_member_hook<>,
                            & Test::order_hook > order_hook_type;
};

This works fine on g++ but on windows it's giving following error:

test.cpp(11) : error C2327: 'Test::order_hook' : is not a type name, static, or enumerator
test.cpp(11) : error C2065: 'order_hook' : undeclared identifier

Please help. What i am missing for windows?

like image 739
Abhi Avatar asked Oct 24 '13 10:10

Abhi


1 Answers

tl;dr: Visual Studio has a bug: your code is legal.


[C++11: 14.3.2/1]: A template-argument for a non-type, non-template template-parameter shall be one of:

  • for a non-type template-parameter of integral or enumeration type, a converted constant expression (5.19) of the type of the template-parameter; or
  • the name of a non-type template-parameter; or
  • a constant expression (5.19) that designates the address of an object with static storage duration and external or internal linkage or a function with external or internal linkage, including function templates and function template-ids but excluding non-static class members, expressed (ignoring parentheses) as & id-expression, except that the & may be omitted if the name refers to a function or array and shall be omitted if the corresponding template-parameter is a reference; or
  • a constant expression that evaluates to a null pointer value (4.10); or
  • a constant expression that evaluates to a null member pointer value (4.11); or
  • a pointer to member expressed as described in 5.3.1.

[C++11: 5.3.1/3]: The result of the unary & operator is a pointer to its operand. The operand shall be an lvalue or a qualified-id. If the operand is a qualified-id naming a non-static member m of some class C with type T, the result has type “pointer to member of class C of type T” and is a prvalue designating C::m. [..]

[C++11: 3.4.3.1/1]: If the nested-name-specifier of a qualified-id nominates a class, the name specified after the nested-name-specifier is looked up in the scope of the class (10.2), except for the cases listed below. The name shall represent one or more members of that class or of one of its base classes (Clause 10). [ Note: A class member can be referred to using a qualified-id at any point in its potential scope (3.3.7). —end note ] The exceptions to the name lookup rule above are the following:

  • a destructor name is looked up as specified in 3.4.3;
  • a conversion-type-id of a conversion-function-id is looked up in the same manner as a conversion-type-id in a class member access (see 3.4.5);
  • the names in a template-argument of a template-id are looked up in the context in which the entire postfix-expression occurs.
  • the lookup for a name specified in a using-declaration (7.3.3) also finds class or enumeration names hidden within the same scope (3.3.10).

None of the exceptions apply here, so we look at the class member's "potential scope":

[C++11: 3.3.7/1]: The following rules describe the scope of names declared in classes.

  1. The potential scope of a name declared in a class consists not only of the declarative region following the name’s point of declaration, but also of all function bodies, brace-or-equal-initializers of non-static data members, and default arguments in that class (including such things in nested classes).
  2. [..]

GCC correctly compiles and executes the following testcase:

template <typename B, int B::* PTM>
struct A {};

struct B
{
    int x;

    typedef A<B, &B::x> a;
};

int main() {
    B b;
}

whereas Visual Studio 2012 Express incorrectly errors out:

1>------ Build started: Project: test1, Configuration: Debug Win32 ------
1> test.cpp
1>f:\documents\visual studio 2012\projects\test1\test1\test.cpp(8): error C2327: 'B::x' : is not a type name, static, or enumerator
1>f:\documents\visual studio 2012\projects\test1\test1\test.cpp(8): error C2065: 'x' : undeclared identifier
1>f:\documents\visual studio 2012\projects\test1\test1\test.cpp(8): error C2975: 'PTM' : invalid template argument for 'A', expected compile-time constant expression
1> f:\documents\visual studio 2012\projects\test1\test1\test.cpp(1) : see declaration of 'PTM'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

like image 128
Lightness Races in Orbit Avatar answered Nov 13 '22 03:11

Lightness Races in Orbit