2013-08-13 05:54:01 +08:00
// RUN: %clang_cc1 -fsyntax-only -std=c++98 -verify -fblocks %s
2008-11-09 01:17:31 +08:00
namespace A {
struct C {
static int cx ;
2009-03-12 07:52:16 +08:00
static int cx2 ;
static int Ag1 ( ) ;
static int Ag2 ( ) ;
2008-11-09 01:17:31 +08:00
} ;
2014-04-14 00:52:03 +08:00
int ax ; // expected-note {{'ax' declared here}}
2008-11-09 01:17:31 +08:00
void Af ( ) ;
}
A : : ; // expected-error {{expected unqualified-id}}
2015-01-19 03:05:48 +08:00
: : A : : ax : : undef ex3 ; // expected-error {{'ax' is not a class, namespace, or enumeration}}
2010-04-08 07:29:58 +08:00
A : : undef1 : : undef2 ex4 ; // expected-error {{no member named 'undef1'}}
2008-11-09 01:17:31 +08:00
2009-03-12 07:52:16 +08:00
int A : : C : : Ag1 ( ) { return 0 ; }
2009-04-02 07:51:29 +08:00
static int A : : C : : Ag2 ( ) { return 0 ; } // expected-error{{'static' can}}
2009-03-12 07:52:16 +08:00
int A : : C : : cx = 17 ;
2009-04-02 07:51:29 +08:00
static int A : : C : : cx2 = 17 ; // expected-error{{'static' can}}
2009-03-12 07:52:16 +08:00
2008-11-09 01:17:31 +08:00
class C2 {
2011-10-11 02:01:37 +08:00
void m ( ) ; // expected-note{{member declaration does not match because it is not const qualified}}
2008-12-16 07:53:10 +08:00
2011-08-05 01:40:00 +08:00
void f ( const int & parm ) ; // expected-note{{type of 1st parameter of member declaration does not match definition ('const int &' vs 'int')}}
2011-10-11 02:01:37 +08:00
void f ( int ) const ; // expected-note{{member declaration does not match because it is const qualified}}
2008-12-16 07:53:10 +08:00
void f ( float ) ;
2008-11-09 01:17:31 +08:00
int x ;
} ;
2010-03-10 19:27:22 +08:00
void C2 : : m ( ) const { } // expected-error{{out-of-line definition of 'm' does not match any declaration in 'C2'}}
2008-12-16 07:53:10 +08:00
2010-03-10 19:27:22 +08:00
void C2 : : f ( int ) { } // expected-error{{out-of-line definition of 'f' does not match any declaration in 'C2'}}
2008-12-16 07:53:10 +08:00
2008-11-09 01:17:31 +08:00
void C2 : : m ( ) {
x = 0 ;
}
namespace B {
2012-04-13 12:07:40 +08:00
void : : A : : Af ( ) { } // expected-error {{cannot define or redeclare 'Af' here because namespace 'B' does not enclose namespace 'A'}}
2008-11-09 01:17:31 +08:00
}
void f1 ( ) {
2008-12-16 07:53:10 +08:00
void A : : Af ( ) ; // expected-error {{definition or redeclaration of 'Af' not allowed inside a function}}
2013-08-13 05:54:01 +08:00
void ( ^ x ) ( ) = ^ { void A : : Af ( ) ; } ; // expected-error {{definition or redeclaration of 'Af' not allowed inside a block}}
2008-11-09 01:17:31 +08:00
}
void f2 ( ) {
A : : ; // expected-error {{expected unqualified-id}}
A : : C : : undef = 0 ; // expected-error {{no member named 'undef'}}
: : A : : C : : cx = 0 ;
int x = : : A : : ax = A : : C : : cx ;
x = sizeof ( A : : C ) ;
x = sizeof ( : : A : : C : : cx ) ;
}
A : : C c1 ;
struct A : : C c2 ;
struct S : public A : : C { } ;
2010-04-01 07:17:41 +08:00
struct A : : undef ; // expected-error {{no struct named 'undef' in namespace 'A'}}
2008-11-09 01:17:31 +08:00
2008-11-10 07:41:00 +08:00
namespace A2 {
typedef int INT ;
struct RC ;
2008-11-20 02:01:13 +08:00
struct CC {
struct NC ;
} ;
2008-11-10 07:41:00 +08:00
}
struct A2 : : RC {
INT x ;
} ;
2008-11-20 02:01:13 +08:00
struct A2 : : CC : : NC {
void m ( ) { }
} ;
2008-11-09 01:17:31 +08:00
void f3 ( ) {
N : : x = 0 ; // expected-error {{use of undeclared identifier 'N'}}
2014-02-09 14:54:23 +08:00
// FIXME: Consider including the kind of entity that 'N' is ("variable 'N'
// declared here", "template 'X' declared here", etc) to help explain what it
// is if it's 'not a class, namespace, or scoped enumeration'.
int N ; // expected-note {{'N' declared here}}
2015-01-19 03:05:48 +08:00
N : : x = 0 ; // expected-error {{'N' is not a class, namespace, or enumeration}}
2008-11-09 01:17:31 +08:00
{ int A ; A : : ax = 0 ; }
2015-01-19 03:05:48 +08:00
{ typedef int A ; A : : ax = 0 ; } // expected-error{{'A' (aka 'int') is not a class, namespace, or enumeration}}
2008-11-09 01:17:31 +08:00
{ typedef A : : C A ; A : : ax = 0 ; } // expected-error {{no member named 'ax'}}
{ typedef A : : C A ; A : : cx = 0 ; }
}
2008-11-19 23:22:16 +08:00
// make sure the following doesn't hit any asserts
2012-08-18 08:55:03 +08:00
void f4 ( undef : : C ) ; // expected-error {{use of undeclared identifier 'undef'}}
2008-12-16 07:53:10 +08:00
typedef void C2 : : f5 ( int ) ; // expected-error{{typedef declarator cannot be qualified}}
void f6 ( int A2 : : RC : : x ) ; // expected-error{{parameter declarator cannot be qualified}}
int A2 : : RC : : x ; // expected-error{{non-static data member defined out-of-line}}
2010-07-16 13:46:45 +08:00
void A2 : : CC : : NC : : m ( ) ; // expected-error{{out-of-line declaration of a member must be a definition}}
2008-12-16 14:37:47 +08:00
namespace E {
int X = 5 ;
namespace Nested {
enum E {
X = 0
} ;
2015-01-19 04:04:35 +08:00
int f ( ) {
return E : : X ; // expected-warning{{use of enumeration in a nested name specifier is a C++11 extension}}
2008-12-16 14:37:47 +08:00
}
}
}
2008-12-26 23:00:45 +08:00
class Operators {
2011-10-11 02:01:37 +08:00
Operators operator + ( const Operators & ) const ; // expected-note{{member declaration does not match because it is const qualified}}
2008-12-26 23:00:45 +08:00
operator bool ( ) ;
} ;
2010-03-10 19:27:22 +08:00
Operators Operators : : operator + ( const Operators & ) { // expected-error{{out-of-line definition of 'operator+' does not match any declaration in 'Operators'}}
2008-12-26 23:00:45 +08:00
Operators ops ;
return ops ;
}
Operators Operators : : operator + ( const Operators & ) const {
Operators ops ;
return ops ;
}
Operators : : operator bool ( ) {
return true ;
}
2009-02-07 01:46:57 +08:00
namespace A {
2011-08-05 01:40:00 +08:00
void g ( int & ) ; // expected-note{{type of 1st parameter of member declaration does not match definition ('int &' vs 'const int &')}}
2009-02-07 01:46:57 +08:00
}
2013-12-14 09:07:05 +08:00
void A : : f ( ) { } // expected-error-re{{out-of-line definition of 'f' does not match any declaration in namespace 'A'{{$}}}}
2009-02-07 01:46:57 +08:00
2009-10-14 05:16:44 +08:00
void A : : g ( const int & ) { } // expected-error{{out-of-line definition of 'g' does not match any declaration in namespace 'A'}}
2009-02-07 01:46:57 +08:00
struct Struct { } ;
2010-03-10 19:27:22 +08:00
void Struct : : f ( ) { } // expected-error{{out-of-line definition of 'f' does not match any declaration in 'Struct'}}
2009-02-07 01:46:57 +08:00
void global_func ( int ) ;
void global_func2 ( int ) ;
namespace N {
void : : global_func ( int ) { } // expected-error{{definition or redeclaration of 'global_func' cannot name the global scope}}
void f ( ) ;
// FIXME: if we move this to a separate definition of N, things break!
}
2013-12-05 15:51:02 +08:00
void : : global_func2 ( int ) { } // expected-warning{{extra qualification on member 'global_func2'}}
2009-02-07 01:46:57 +08:00
void N : : f ( ) { } // okay
2009-03-07 03:06:37 +08:00
2010-03-10 19:27:22 +08:00
struct Y ; // expected-note{{forward declaration of 'Y'}}
2010-04-09 00:38:48 +08:00
Y : : foo y ; // expected-error{{incomplete type 'Y' named in nested name specifier}}
2009-03-12 00:48:53 +08:00
2017-06-12 04:33:00 +08:00
namespace PR25156 {
struct Y ; // expected-note{{forward declaration of 'PR25156::Y'}}
void foo ( ) {
Y : : ~ Y ( ) ; // expected-error{{incomplete type 'PR25156::Y' named in nested name specifier}}
}
}
2013-10-15 08:00:26 +08:00
X : : X ( ) : a ( 5 ) { } // expected-error{{use of undeclared identifier 'X'}}
2009-06-26 12:27:47 +08:00
2009-07-21 14:43:26 +08:00
struct foo_S {
static bool value ;
} ;
bool ( foo_S : : value ) ;
2009-06-26 12:27:47 +08:00
namespace somens {
2010-01-13 08:25:19 +08:00
struct a { } ; // expected-note{{candidate constructor (the implicit copy constructor)}}
2009-06-26 12:27:47 +08:00
}
template < typename T >
class foo {
} ;
2009-12-07 09:36:53 +08:00
// PR4452 / PR4451
foo < somens : a > a2 ; // expected-error {{unexpected ':' in nested name specifier}}
2009-06-26 12:27:47 +08:00
2009-12-19 11:01:41 +08:00
somens : : a a3 = a2 ; // expected-error {{no viable conversion}}
2009-06-26 12:27:47 +08:00
2009-12-18 18:40:03 +08:00
// typedefs and using declarations.
namespace test1 {
namespace ns {
2010-04-10 03:03:51 +08:00
class Counter { public : static int count ; } ;
2009-12-18 18:40:03 +08:00
typedef Counter counter ;
}
using ns : : counter ;
2009-06-26 12:27:47 +08:00
2009-12-18 18:40:03 +08:00
class Test {
void test1 ( ) {
counter c ;
c . count + + ;
counter : : count + + ;
}
} ;
}
2009-12-19 17:28:58 +08:00
// We still need to do lookup in the lexical scope, even if we push a
// non-lexical scope.
namespace test2 {
namespace ns {
2010-01-27 02:52:33 +08:00
extern int * count_ptr ;
2009-12-19 17:28:58 +08:00
}
namespace {
int count = 0 ;
}
int * ns : : count_ptr = & count ;
}
2010-02-09 03:26:07 +08:00
// PR6259, invalid case
namespace test3 {
2010-04-09 00:38:48 +08:00
class A ; // expected-note {{forward declaration}}
2010-02-09 03:26:07 +08:00
void foo ( const char * path ) {
2010-04-09 00:38:48 +08:00
A : : execute ( path ) ; // expected-error {{incomplete type 'test3::A' named in nested name specifier}}
2010-02-09 03:26:07 +08:00
}
}
2010-05-14 12:53:42 +08:00
namespace PR7133 {
namespace A {
class Foo ;
}
namespace A {
namespace B {
bool foo ( Foo & ) ;
}
}
bool A : : B : : foo ( Foo & ) {
return false ;
}
}
2010-10-02 05:19:28 +08:00
class CLASS {
2012-09-14 04:16:20 +08:00
void CLASS : : foo2 ( ) ; // expected-error {{extra qualification on member 'foo2'}}
2010-10-02 05:19:28 +08:00
} ;
2010-10-14 06:19:53 +08:00
namespace PR8159 {
class B { } ;
class A {
2012-09-14 04:16:20 +08:00
int A : : a ; // expected-error{{extra qualification on member 'a'}}
static int A : : b ; // expected-error{{extra qualification on member 'b'}}
2010-10-14 06:19:53 +08:00
int : : c ; // expected-error{{non-friend class member 'c' cannot have a qualified name}}
} ;
}
2011-02-05 13:54:49 +08:00
namespace rdar7980179 {
class A { void f0 ( ) ; } ; // expected-note {{previous}}
2013-08-23 10:16:48 +08:00
int A : : f0 ( ) { } // expected-error {{return type of out-of-line definition of 'rdar7980179::A::f0' differs}}
2011-02-05 13:54:49 +08:00
}
2011-02-24 10:37:39 +08:00
namespace alias = A ;
double * dp = ( alias : : C * ) 0 ; // expected-error{{cannot initialize a variable of type 'double *' with an rvalue of type 'alias::C *'}}
2011-06-25 03:59:27 +08:00
// http://llvm.org/PR10109
namespace PR10109 {
template < typename T >
struct A {
protected :
struct B ;
struct B : : C ; / / expected - error { { requires a template parameter list } } \
2012-03-18 07:06:31 +08:00
/ / expected - error { { no struct named ' C ' } } \
// expected-error{{non-friend class member 'C' cannot have a qualified name}}
2011-06-25 03:59:27 +08:00
} ;
template < typename T >
struct A2 {
protected :
struct B ;
} ;
template < typename T >
struct A2 < T > : : B : : C ; // expected-error {{no struct named 'C'}}
}
2012-06-07 04:54:51 +08:00
namespace PR13033 {
namespace NS {
int a ; // expected-note {{'NS::a' declared here}}
int longer_b ; //expected-note {{'NS::longer_b' declared here}}
}
// Suggest adding a namespace qualifier to both variable names even though one
// is only a single character long.
int foobar = a + longer_b ; / / expected - error { { use of undeclared identifier ' a ' ; did you mean ' NS : : a ' ? } } \
// expected-error {{use of undeclared identifier 'longer_b'; did you mean 'NS::longer_b'?}}
}
2013-05-15 07:22:32 +08:00
// <rdar://problem/13853540>
namespace N {
struct X { } ;
namespace N {
struct Foo {
struct N : : X * foo ( ) ; // expected-error{{no struct named 'X' in namespace 'N::N'}}
} ;
}
}
2013-06-20 06:58:30 +08:00
namespace TypedefNamespace { typedef int F ; } ;
2017-03-10 23:04:58 +08:00
TypedefNamespace : : F : : NonexistentName BadNNSWithCXXScopeSpec ; // expected-error {{'TypedefNamespace::F' (aka 'int') is not a class, namespace, or enumeration}}
2014-07-16 13:16:52 +08:00
namespace PR18587 {
struct C1 {
int a , b , c ;
typedef int C2 ;
struct B1 {
struct B2 {
int a , b , c ;
} ;
} ;
} ;
struct C2 { static const unsigned N1 = 1 ; } ;
struct B1 {
enum E1 { B2 = 2 } ;
static const int B3 = 3 ;
} ;
const int N1 = 2 ;
// Function declarators
struct S1a { int f ( C1 : : C2 ) ; } ;
struct S1b { int f ( C1 : C2 ) ; } ; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
struct S2a {
C1 : : C2 f ( C1 : : C2 ) ;
} ;
struct S2c {
C1 : : C2 f ( C1 : C2 ) ; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
} ;
struct S3a {
int f ( C1 : : C2 ) , C2 : N1 ;
int g : B1 : : B2 ;
} ;
struct S3b {
int g : B1 : B2 ; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
} ;
// Inside square brackets
struct S4a {
int f [ C2 : : N1 ] ;
} ;
struct S4b {
int f [ C2 : N1 ] ; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
} ;
struct S5a {
int f ( int xx [ B1 : : B3 ? C2 : : N1 : B1 : : B2 ] ) ;
} ;
struct S5b {
int f ( int xx [ B1 : : B3 ? C2 : : N1 : B1 : B2 ] ) ; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
} ;
struct S5c {
int f ( int xx [ B1 : B3 ? C2 : : N1 : B1 : : B2 ] ) ; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
} ;
// Bit fields
struct S6a {
C1 : : C2 m1 : B1 : : B2 ;
} ;
struct S6c {
C1 : : C2 m1 : B1 : B2 ; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
} ;
struct S6d {
int C2 : N1 ;
} ;
struct S6e {
static const int N = 3 ;
B1 : : E1 : N ;
} ;
struct S6g {
C1 : : C2 : B1 : B2 ; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
B1 : : E1 : B1 : B2 ; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
} ;
// Template parameters
template < int N > struct T1 {
int a , b , c ;
static const unsigned N1 = N ;
typedef unsigned C1 ;
} ;
T1 < C2 : : N1 > var_1a ;
T1 < C2 : N1 > var_1b ; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
template < int N > int F ( ) { }
int ( * X1 ) ( ) = ( B1 : : B2 ? F < 1 > : F < 2 > ) ;
int ( * X2 ) ( ) = ( B1 : B2 ? F < 1 > : F < 2 > ) ; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
// Bit fields + templates
struct S7a {
T1 < B1 : : B2 > : : C1 m1 : T1 < B1 : : B2 > : : N1 ;
} ;
struct S7b {
T1 < B1 : B2 > : : C1 m1 : T1 < B1 : : B2 > : : N1 ; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
} ;
struct S7c {
T1 < B1 : : B2 > : : C1 m1 : T1 < B1 : B2 > : : N1 ; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
} ;
}
2015-01-19 04:04:35 +08:00
namespace PR16951 {
namespace ns {
enum an_enumeration {
ENUMERATOR // expected-note{{'ENUMERATOR' declared here}}
} ;
}
int x1 = ns : : an_enumeration : : ENUMERATOR ; // expected-warning{{use of enumeration in a nested name specifier is a C++11 extension}}
int x2 = ns : : an_enumeration : : ENUMERATOR : : vvv ; / / expected - warning { { use of enumeration in a nested name specifier is a C + + 11 extension } } \
/ / expected - error { { ' ENUMERATOR ' is not a class , namespace , or enumeration } } \
int x3 = ns : : an_enumeration : : X ; / / expected - warning { { use of enumeration in a nested name specifier is a C + + 11 extension } } \
// expected-error{{no member named 'X'}}
enum enumerator_2 {
ENUMERATOR_2
} ;
int x4 = enumerator_2 : : ENUMERATOR_2 ; // expected-warning{{use of enumeration in a nested name specifier is a C++11 extension}}
int x5 = enumerator_2 : : X2 ; / / expected - warning { { use of enumeration in a nested name specifier is a C + + 11 extension } } \
// expected-error{{no member named 'X2' in 'PR16951::enumerator_2'}}
}
2016-10-28 08:15:24 +08:00
namespace PR30619 {
c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ;
// expected-error@-1 16{{unknown type name 'c'}}
c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ;
// expected-error@-1 16{{unknown type name 'c'}}
c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ;
// expected-error@-1 16{{unknown type name 'c'}}
c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ; c d ;
// expected-error@-1 16{{unknown type name 'c'}}
namespace A {
class B {
typedef C D ; // expected-error{{unknown type name 'C'}}
A : : D : : F ;
2017-03-10 23:04:58 +08:00
// expected-error@-1{{'PR30619::A::B::D' (aka 'int') is not a class, namespace, or enumeration}}
2016-10-28 08:15:24 +08:00
} ;
}
}