Home | History | Annotate | Download | only in SemaCXX
      1 // RUN: %clang_cc1 -fsyntax-only -std=c++1y -DCXX1Y -Wc++98-compat-pedantic -verify %s -DCXX1Y2
      2 // RUN: %clang_cc1 -fsyntax-only -std=c++1y -DCXX1Y -Wc++98-compat -Werror %s -DCXX1Y2
      3 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wc++98-compat-pedantic -verify %s
      4 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wc++98-compat -Werror %s
      5 // RUN: %clang_cc1 -fsyntax-only -std=c++98 -Werror %s -DCXX98
      6 
      7 // RUN: %clang_cc1 -fsyntax-only -std=c++1y -Wc++98-compat-pedantic -verify %s -Wno-c++98-c++11-compat-pedantic -DCXX1Y2
      8 
      9 // -Wc++98-compat-pedantic warns on C++11 features which we accept without a
     10 // warning in C++98 mode.
     11 
     12 #line 32767 // ok
     13 #line 32768 // expected-warning {{#line number greater than 32767 is incompatible with C++98}}
     14 
     15 #define VA_MACRO(x, ...) x // expected-warning {{variadic macros are incompatible with C++98}}
     16 VA_MACRO(,x) // expected-warning {{empty macro arguments are incompatible with C++98}}
     17 
     18 ; // expected-warning {{extra ';' outside of a function is incompatible with C++98}}
     19 
     20 enum Enum {
     21   Enum_value, // expected-warning {{commas at the end of enumerator lists are incompatible with C++98}}
     22 };
     23 
     24 template<typename T> struct InstantiationAfterSpecialization {};
     25 template<> struct InstantiationAfterSpecialization<int> {}; // expected-note {{here}}
     26 template struct InstantiationAfterSpecialization<int>; // expected-warning {{explicit instantiation of 'InstantiationAfterSpecialization<int>' that occurs after an explicit specialization is incompatible with C++98}}
     27 
     28 void *dlsym();
     29 void (*FnPtr)() = (void(*)())dlsym(); // expected-warning {{cast between pointer-to-function and pointer-to-object is incompatible with C++98}}
     30 void *FnVoidPtr = (void*)&dlsym; // expected-warning {{cast between pointer-to-function and pointer-to-object is incompatible with C++98}}
     31 
     32 struct ConvertToInt {
     33   operator int();
     34 };
     35 int *ArraySizeConversion = new int[ConvertToInt()];
     36 #ifdef CXX1Y2
     37 // expected-warning@-2 {{implicit conversion from array size expression of type 'ConvertToInt' to integral type 'size_t' is incompatible with C++98}}
     38 #else
     39 // expected-warning@-4 {{implicit conversion from array size expression of type 'ConvertToInt' to integral type 'int' is incompatible with C++98}}
     40 #endif
     41 
     42 template<typename T> class ExternTemplate {};
     43 extern template class ExternTemplate<int>; // expected-warning {{extern templates are incompatible with C++98}}
     44 
     45 long long ll1 = // expected-warning {{'long long' is incompatible with C++98}}
     46          -42LL; // expected-warning {{'long long' is incompatible with C++98}}
     47 unsigned long long ull1 = // expected-warning {{'long long' is incompatible with C++98}}
     48                    42ULL; // expected-warning {{'long long' is incompatible with C++98}}
     49 
     50 int k = 0b1001;
     51 #ifdef CXX1Y
     52 // expected-warning@-2 {{binary integer literals are incompatible with C++ standards before C++14}}
     53 #endif
     54 
     55 namespace CopyCtorIssues {
     56   struct Private {
     57     Private();
     58   private:
     59     Private(const Private&); // expected-note {{declared private here}}
     60   };
     61   struct NoViable {
     62     NoViable();
     63     NoViable(NoViable&); // expected-note {{not viable}}
     64   };
     65   struct Ambiguous {
     66     Ambiguous();
     67     Ambiguous(const Ambiguous &, int = 0); // expected-note {{candidate}}
     68     Ambiguous(const Ambiguous &, double = 0); // expected-note {{candidate}}
     69   };
     70   struct Deleted {
     71     Private p; // expected-note {{implicitly deleted}}
     72   };
     73 
     74   const Private &a = Private(); // expected-warning {{copying variable of type 'CopyCtorIssues::Private' when binding a reference to a temporary would invoke an inaccessible constructor in C++98}}
     75   const NoViable &b = NoViable(); // expected-warning {{copying variable of type 'CopyCtorIssues::NoViable' when binding a reference to a temporary would find no viable constructor in C++98}}
     76 #if !CXX98
     77   const Ambiguous &c = Ambiguous(); // expected-warning {{copying variable of type 'CopyCtorIssues::Ambiguous' when binding a reference to a temporary would find ambiguous constructors in C++98}}
     78 #endif
     79   const Deleted &d = Deleted(); // expected-warning {{copying variable of type 'CopyCtorIssues::Deleted' when binding a reference to a temporary would invoke a deleted constructor in C++98}}
     80 }
     81