brintos

brintos / llvm-project-archived public Read only

0
0
Text · 15.8 KiB · c60275b Raw
519 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -std=c++98 -verify=expected,cxx98,cxx98-11 -fblocks %s2// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify=expected,since-cxx11,cxx98-11 -fblocks %s3// RUN: %clang_cc1 -fsyntax-only -std=c++14 -verify=expected,since-cxx11 -fblocks %s4// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify=expected,since-cxx11 -fblocks %s5// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify=expected,since-cxx11,since-cxx20 -fblocks %s6// RUN: %clang_cc1 -fsyntax-only -std=c++23 -verify=expected,since-cxx11,since-cxx20 -fblocks %s7// RUN: %clang_cc1 -fsyntax-only -std=c++26 -verify=expected,since-cxx11,since-cxx20 -fblocks %s8 9namespace A {10  struct C {11    static int cx;12 13    static int cx2;14 15    static int Ag1();16    static int Ag2();17  };18  int ax;19  // expected-note@-1 {{'ax' declared here}}20  // expected-note@-2 {{'::A::ax' declared here}}21  void Af();22}23 24A:: ; // expected-error {{expected unqualified-id}}25::A::ax::undef ex3; // expected-error {{'ax' is not a class, namespace, or enumeration}}26A::undef1::undef2 ex4; // expected-error {{no member named 'undef1'}}27 28int A::C::Ag1() { return 0; }29 30static int A::C::Ag2() { return 0; } // expected-error{{'static' can}}31 32int A::C::cx = 17;33 34 35static int A::C::cx2 = 17; // expected-error{{'static' can}}36 37class C2 { // #defined-here-C238  void m(); // expected-note{{member declaration does not match because it is not const qualified}}39 40  void f(const int& parm); // expected-note{{type of 1st parameter of member declaration does not match definition ('const int &' vs 'int')}}41  void f(int) const; // expected-note{{member declaration does not match because it is const qualified}}42  void f(float);43 44  int x;45};46 47void C2::m() const { } // expected-error{{out-of-line definition of 'm' does not match any declaration in 'C2'}}48                       // expected-note@#defined-here-C2{{defined here}}49 50void C2::f(int) { } // expected-error{{out-of-line definition of 'f' does not match any declaration in 'C2'}}51                    // expected-note@#defined-here-C2{{defined here}}52 53void C2::m() {54  x = 0;55}56 57namespace B {58  void ::A::Af() {} // expected-error {{cannot define or redeclare 'Af' here because namespace 'B' does not enclose namespace 'A'}}59}60 61void f1() {62  void A::Af(); // expected-error {{definition or redeclaration of 'Af' not allowed inside a function}}63  void (^x)() = ^{ void A::Af(); }; // expected-error {{definition or redeclaration of 'Af' not allowed inside a block}}64}65 66void f2() {67  A:: ; // expected-error {{expected unqualified-id}}68  A::C::undef = 0; // expected-error {{no member named 'undef'}}69  ::A::C::cx = 0;70  int x = ::A::ax = A::C::cx;71  x = sizeof(A::C);72  x = sizeof(::A::C::cx);73}74 75A::C c1;76struct A::C c2;77struct S : public A::C {};78struct A::undef; // expected-error {{no struct named 'undef' in namespace 'A'}}79                 // expected-error@-1 {{forward declaration of struct cannot have a nested name specifier}}80namespace A2 {81  typedef int INT;82  struct RC;83  struct CC {84    struct NC;85  };86}87 88struct A2::RC {89  INT x;90};91 92struct A2::CC::NC {93  void m() {}94};95 96void f3() {97  N::x = 0; // expected-error {{use of undeclared identifier 'N'}}98  // FIXME: Consider including the kind of entity that 'N' is ("variable 'N'99  // declared here", "template 'X' declared here", etc) to help explain what it100  // is if it's 'not a class, namespace, or scoped enumeration'.101  int N; // expected-note {{'N' declared here}}102  N::x = 0; // expected-error {{'N' is not a class, namespace, or enumeration}}103  { int A;           A::ax = 0; }104  { typedef int A;   A::ax = 0; } // expected-error{{'A' (aka 'int') is not a class, namespace, or enumeration}}105  { typedef A::C A;  A::ax = 0; } // expected-error {{no member named 'ax' in 'A::C'; did you mean '::A::ax'?}}106  { typedef A::C A;  A::cx = 0; }107}108 109// make sure the following doesn't hit any asserts110void f4(undef::C); // expected-error {{use of undeclared identifier 'undef'}}111 112typedef void C2::f5(int); // expected-error{{typedef declarator cannot be qualified}}113 114void f6(int A2::RC::x); // expected-error{{parameter declarator cannot be qualified}}115 116int A2::RC::x; // expected-error{{non-static data member defined out-of-line}}117 118void A2::CC::NC::m(); // expected-error{{out-of-line declaration of a member must be a definition}}119 120 121namespace E {122  int X = 5;123 124  namespace Nested {125    enum E {126      X = 0127    };128 129    int f() {130      return E::X; // cxx98-warning{{use of enumeration in a nested name specifier is a C++11 extension}}131    }132  }133}134 135 136class Operators { // #defined-here-Operators137  Operators operator+(const Operators&) const; // expected-note{{member declaration does not match because it is const qualified}}138  operator bool();139};140 141Operators Operators::operator+(const Operators&) { // expected-error{{out-of-line definition of 'operator+' does not match any declaration in 'Operators'}}142                                                   // expected-note@#defined-here-Operators{{defined here}}143  Operators ops;144  return ops;145}146 147Operators Operators::operator+(const Operators&) const {148  Operators ops;149  return ops;150}151 152Operators::operator bool() {153  return true;154}155 156namespace A {157  void g(int&); // expected-note{{type of 1st parameter of member declaration does not match definition ('int &' vs 'const int &')}}158}159 160void A::f() {} // expected-error-re{{out-of-line definition of 'f' does not match any declaration in namespace 'A'{{$}}}}161 162void A::g(const int&) { } // expected-error{{out-of-line definition of 'g' does not match any declaration in namespace 'A'}}163 164struct Struct { }; // #defined-here-Struct165 166void Struct::f() { } // expected-error{{out-of-line definition of 'f' does not match any declaration in 'Struct'}}167                     // expected-note@#defined-here-Struct{{defined here}}168 169void global_func(int);170void global_func2(int);171 172namespace N {173  void ::global_func(int) { } // expected-error{{definition or redeclaration of 'global_func' cannot name the global scope}}174 175  void f();176  // FIXME: if we move this to a separate definition of N, things break!177}178void ::global_func2(int) { } // expected-warning{{extra qualification on member 'global_func2'}}179 180void N::f() { } // okay181 182// FIXME (GH147000): duplicate diagnostics183struct Y;  // expected-note{{forward declaration of 'Y'}} since-cxx20-note{{forward declaration of 'Y'}}184Y::foo y; // expected-error{{incomplete type 'Y' named in nested name specifier}} since-cxx20-error{{incomplete type 'Y' named in nested name specifier}}185 186namespace PR25156 {187struct Y;  // expected-note{{forward declaration of 'PR25156::Y'}}188void foo() {189  Y::~Y(); // expected-error{{incomplete type 'PR25156::Y' named in nested name specifier}}190}191}192 193X::X() : a(5) { } // expected-error{{use of undeclared identifier 'X'}}194 195struct foo_S {196  static bool value;197};198bool (foo_S::value);199 200 201namespace somens {202  struct a { };203  // expected-note@-1 {{candidate constructor (the implicit copy constructor)}}204  // since-cxx11-note@-2 {{candidate constructor (the implicit move constructor)}}205}206 207template <typename T>208class foo {209};210 211 212// PR4452 / PR4451213foo<somens:a> a2;  // expected-error {{unexpected ':' in nested name specifier}}214 215somens::a a3 = a2; // expected-error {{no viable conversion}}216 217// typedefs and using declarations.218namespace test1 {219  namespace ns {220    class Counter { public: static int count; };221    typedef Counter counter;222  }223  using ns::counter;224 225  class Test {226    void test1() {227      counter c;228      c.count++;229      counter::count++;230    }231  };232}233 234// We still need to do lookup in the lexical scope, even if we push a235// non-lexical scope.236namespace test2 {237  namespace ns {238    extern int *count_ptr;239  }240  namespace {241    int count = 0;242  }243 244  int *ns::count_ptr = &count;245}246 247// PR6259, invalid case248namespace test3 {249  class A; // expected-note {{forward declaration}}250  void foo(const char *path) {251    A::execute(path); // expected-error {{incomplete type 'test3::A' named in nested name specifier}}252  }253}254 255namespace PR7133 {256  namespace A {257    class Foo;258  }259 260  namespace A {261    namespace B {262      bool foo(Foo &);263    }264  }265 266  bool A::B::foo(Foo &) {267    return false;268  }269}270 271class CLASS {272  void CLASS::foo2(); // expected-error {{extra qualification on member 'foo2'}}273};274 275namespace PR8159 {276  class B { };277 278  class A {279    int A::a; // expected-error{{extra qualification on member 'a'}}280    static int A::b; // expected-error{{extra qualification on member 'b'}}281    int ::c; // expected-error{{non-friend class member 'c' cannot have a qualified name}}282  };283}284 285namespace rdar7980179 {286  class A { void f0(); }; // expected-note {{previous}}287  int A::f0() {} // expected-error {{return type of out-of-line definition of 'rdar7980179::A::f0' differs}}288}289 290namespace alias = A;291double *dp = (alias::C*)0; // expected-error{{cannot initialize a variable of type 'double *' with an rvalue of type 'alias::C *'}}292 293// http://llvm.org/PR10109294namespace PR10109 {295template<typename T>296struct A {297protected:298  struct B;299  struct B::C;300  // expected-error@-1 {{requires a template parameter list}}301  // expected-error@-2 {{no struct named 'C'}}302  // expected-error@-3 {{non-friend class member 'C' cannot have a qualified name}}303  // expected-error@-4 {{forward declaration of struct cannot have a nested name specifier}}304};305 306template<typename T>307struct A2 {308protected:309  struct B;310};311template <typename T>312struct A2<T>::B::C; // expected-error {{no struct named 'C'}}313                    // expected-error@-1 {{forward declaration of struct cannot have a nested name specifier}}314}315 316namespace PR13033 {317namespace NS {318 int a; // expected-note {{'NS::a' declared here}}319 int longer_b; //expected-note {{'NS::longer_b' declared here}}320}321 322// Suggest adding a namespace qualifier to both variable names even though one323// is only a single character long.324int foobar = a + longer_b; // expected-error {{use of undeclared identifier 'a'; did you mean 'NS::a'?}} \325                           // expected-error {{use of undeclared identifier 'longer_b'; did you mean 'NS::longer_b'?}}326}327 328namespace N {329  struct X { };330  namespace N {331    struct Foo {332      struct N::X *foo(); // expected-error{{no struct named 'X' in namespace 'N::N'}}333    };334  }335}336 337namespace TypedefNamespace { typedef int F; };338TypedefNamespace::F::NonexistentName BadNNSWithCXXScopeSpec; // expected-error {{'TypedefNamespace::F' (aka 'int') is not a class, namespace, or enumeration}}339 340namespace PR18587 {341 342struct C1 {343  int a, b, c;344  typedef int C2;345  struct B1 {346    struct B2 {347      int a, b, c;348    };349  };350};351struct C2 { static const unsigned N1 = 1; };352struct B1 {353  enum E1 { B2 = 2 };354  static const int B3 = 3;355};356const int N1 = 2;357 358// Function declarators359struct S1a { int f(C1::C2); };360struct S1b { int f(C1:C2); };  // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}361 362struct S2a {363  C1::C2 f(C1::C2);364};365struct S2c {366  C1::C2 f(C1:C2);  // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}367};368 369struct S3a {370  int f(C1::C2), C2 : N1;371  int g : B1::B2;372};373struct S3b {374  int g : B1:B2;  // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}375};376 377// Inside square brackets378struct S4a {379  int f[C2::N1];380};381struct S4b {382  int f[C2:N1];  // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}383};384 385struct S5a {386  int f(int xx[B1::B3 ? C2::N1 : B1::B2]);387};388struct S5b {389  int f(int xx[B1::B3 ? C2::N1 : B1:B2]);  // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}390};391struct S5c {392  int f(int xx[B1:B3 ? C2::N1 : B1::B2]);  // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}393};394 395// Bit fields396struct S6a {397  C1::C2 m1 : B1::B2;398};399struct S6c {400  C1::C2 m1 : B1:B2;  // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}401};402struct S6d {403  int C2:N1;404};405struct S6e {406  static const int N = 3;407  B1::E1 : N;408};409struct S6g {410  C1::C2 : B1:B2;  // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}411  B1::E1 : B1:B2;  // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}412};413 414// Template parameters415template <int N> struct T1 {416  int a,b,c;417  static const unsigned N1 = N;418  typedef unsigned C1;419};420T1<C2::N1> var_1a;421T1<C2:N1> var_1b;  // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}422template<int N> int F() {}423int (*X1)() = (B1::B2 ? F<1> : F<2>);424int (*X2)() = (B1:B2 ? F<1> : F<2>);  // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}} \425                                         expected-note{{'PR18587::X2' declared here}}426 427// Bit fields + templates428struct S7a {429  T1<B1::B2>::C1 m1 : T1<B1::B2>::N1;430};431struct S7b {432  T1<B1:B2>::C1 m1 : T1<B1::B2>::N1;  // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}433};434struct S7c {435  T1<B1::B2>::C1 m1 : T1<B1:B2>::N1;  // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}436};437 438}439 440namespace PR16951 {441  namespace ns {442    enum an_enumeration {443      ENUMERATOR  // expected-note{{'ENUMERATOR' declared here}}444    };445  }446 447  int x1 = ns::an_enumeration::ENUMERATOR; // cxx98-warning{{use of enumeration in a nested name specifier is a C++11 extension}}448 449  int x2 = ns::an_enumeration::ENUMERATOR::vvv; // cxx98-warning{{use of enumeration in a nested name specifier is a C++11 extension}} \450                                                // expected-error{{'ENUMERATOR' is not a class, namespace, or enumeration}} \451 452  int x3 = ns::an_enumeration::X; // cxx98-warning {{use of enumeration in a nested name specifier is a C++11 extension}} \453                                  // expected-error{{no member named 'X'}}454 455  enum enumerator_2 {456    ENUMERATOR_2457  };458 459  int x4 = enumerator_2::ENUMERATOR_2; // cxx98-warning{{use of enumeration in a nested name specifier is a C++11 extension}}460  int x5 = enumerator_2::X2; // cxx98-warning{{use of enumeration in a nested name specifier is a C++11 extension}} \461                             // expected-error{{no member named 'X2' in 'PR16951::enumerator_2'}} \462                             // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'int (*)()'}}463 464}465 466namespace PR30619 {467c 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;468// expected-error@-1 16{{unknown type name 'c'}}469c 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;470// expected-error@-1 16{{unknown type name 'c'}}471c 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;472// expected-error@-1 16{{unknown type name 'c'}}473c 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;474// expected-error@-1 16{{unknown type name 'c'}}475namespace A {476class B {477  typedef C D; // expected-error{{unknown type name 'C'}}478  A::D::F;479  // expected-error@-1{{'A::D' (aka 'int') is not a class, namespace, or enumeration}}480};481}482}483 484namespace DependentTemplateInTrivialNNSLoc {485  // This testcase causes us to create trivial type source info when doing486  // substitution into T::template g<>. That trivial type source info contained487  // a NestedNameSpecifierLoc with no location information.488  //489  // Previously, creating a CXXScopeSpec from that resulted in an invalid scope490  // spec, leading to crashes. Ensure we don't crash here.491  template <typename T> void f(T &x) {492    for (typename T::template g<> i : x) {} // expected-warning 0-1{{extension}}493    x: goto x;494  }495}496 497template <typename T>498struct x; // expected-note {{template is declared here}}499 500template <typename T>501int issue55962 = x::a; // expected-error {{use of class template 'x' requires template arguments}} \502                       // cxx98-11-warning {{variable templates are a C++14 extension}}503 504namespace ForwardDeclared {505  typedef class A B;506  struct A {507    enum C {};508    void F(B::C);509  };510}511 512namespace GH63254 {513template <typename...> struct V {}; // cxx98-warning {{variadic templates are a C++11 extension}}514struct S : V<> {515  using S::V; // expected-error {{using declaration refers to its own class}}516  V<> v; // no crash517};518}519