2009-12-16 04:14:24 +08:00
// RUN: %clang_cc1 -fsyntax-only -std=c++98 -verify %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
} ;
int ax ;
void Af ( ) ;
}
A : : ; // expected-error {{expected unqualified-id}}
2009-10-14 07:27:22 +08:00
: : A : : ax : : undef ex3 ; // expected-error {{no member named}}
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 {
2008-12-16 07:53:10 +08:00
void m ( ) ; // expected-note{{member declaration nearly matches}}
void f ( const int & parm ) ; // expected-note{{member declaration nearly matches}}
void f ( int ) const ; // expected-note{{member declaration nearly matches}}
void f ( float ) ;
2008-11-09 01:17:31 +08:00
int x ;
} ;
2009-10-14 05:16:44 +08:00
void C2 : : m ( ) const { } // expected-error{{out-of-line definition of 'm' does not match any declaration in 'class C2'}}
2008-12-16 07:53:10 +08:00
2009-10-14 05:16:44 +08:00
void C2 : : f ( int ) { } // expected-error{{out-of-line definition of 'f' does not match any declaration in 'class C2'}}
2008-12-16 07:53:10 +08:00
2008-11-09 01:17:31 +08:00
void C2 : : m ( ) {
x = 0 ;
}
namespace B {
2008-11-24 04:28:15 +08:00
void : : A : : Af ( ) { } // expected-error {{definition or redeclaration of 'Af' not in a namespace enclosing '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}}
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 { } ;
struct A : : undef ; // expected-error {{'undef' does not name a tag member in the specified scope}}
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'}}
int N ;
N : : x = 0 ; // expected-error {{expected a class or namespace}}
{ int A ; A : : ax = 0 ; }
2008-12-16 14:37:47 +08:00
{ typedef int A ; A : : ax = 0 ; } // expected-error{{expected a class or namespace}}
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
2009-04-13 06:23:27 +08:00
void f4 ( undef : : C ) ; / / expected - error { { use of undeclared identifier ' undef ' } } \
expected - error { { variable has incomplete type ' void ' } }
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}}
2009-03-24 07:06:20 +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
} ;
void f ( ) {
return E : : X ; // expected-error{{expected a class or namespace}}
}
}
}
2008-12-26 23:00:45 +08:00
class Operators {
Operators operator + ( const Operators & ) const ; // expected-note{{member declaration nearly matches}}
operator bool ( ) ;
} ;
2009-10-14 05:16:44 +08:00
Operators Operators : : operator + ( const Operators & ) { // expected-error{{out-of-line definition of 'operator+' does not match any declaration in 'class 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 {
void g ( int & ) ; // expected-note{{member declaration nearly matches}}
}
2009-10-14 05:16:44 +08:00
void A : : f ( ) { } // expected-error{{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 { } ;
2009-10-14 05:16:44 +08:00
void Struct : : f ( ) { } // expected-error{{out-of-line definition of 'f' does not match any declaration in 'struct 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!
}
void : : global_func2 ( int ) { } // expected-error{{definition or redeclaration of 'global_func2' cannot name the global scope}}
void N : : f ( ) { } // okay
2009-03-07 03:06:37 +08:00
2009-03-12 00:48:53 +08:00
struct Y ; // expected-note{{forward declaration of 'struct Y'}}
Y : : foo y ; / / expected - error { { incomplete type ' struct Y ' named in nested name specifier } } \
2009-10-14 07:27:22 +08:00
// expected-error{{no type named 'foo' in}}
2009-03-12 00:48:53 +08:00
2009-03-07 03:06:37 +08:00
X : : X ( ) : a ( 5 ) { } / / expected - error { { use of undeclared identifier ' X ' } } \
2009-03-25 10:58:17 +08:00
/ / expected - error { { C + + requires a type specifier for all declarations } } \
// expected-error{{only constructors take base initializers}}
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 {
class Counter { static int count ; } ;
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 {
int * count_ptr ;
}
namespace {
int count = 0 ;
}
int * ns : : count_ptr = & count ;
}