brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.5 KiB · acbc1b1 Raw
188 lines · cpp
1// RUN: %clang_cc1 -verify -std=c++11 -Wno-anonymous-pack-parens %s2// RUN: cp %s %t3// RUN: not %clang_cc1 -x c++ -std=c++11 -fixit %t4// RUN: %clang_cc1 -Wall -pedantic -x c++ -std=c++11 %t5 6/* This is a test of the various code modification hints that only7   apply in C++0x. */8struct A {9  explicit operator int(); // expected-note{{conversion to integral type}}10};11 12void x() {13  switch(A()) { // expected-error{{explicit conversion to}}14  }15}16 17using ::T = void; // expected-error {{name defined in alias declaration must be an identifier}}18using typename U = void; // expected-error {{name defined in alias declaration must be an identifier}}19using typename ::V = void; // expected-error {{name defined in alias declaration must be an identifier}}20 21namespace SemiCommaTypo {22  int m {},23  n [[]], // expected-error {{expected ';' at end of declaration}}24  int o;25 26  struct Base {27    virtual void f2(), f3();28  };29  struct MemberDeclarator : Base {30    int k : 4,31        //[[]] : 1, FIXME: test this once we support attributes here32        : 9, // expected-error {{expected ';' at end of declaration}}33    char c, // expected-error {{expected ';' at end of declaration}}34    typedef void F(), // expected-error {{expected ';' at end of declaration}}35    F f1,36      f2 final,37      f3 override, // expected-error {{expected ';' at end of declaration}}38  };39}40 41namespace ScopedEnum {42  enum class E { a };43 44  enum class E b = E::a; // expected-error {{must use 'enum' not 'enum class'}}45  struct S {46    friend enum class E; // expected-error {{must use 'enum' not 'enum class'}}47                         // expected-warning@-1 {{elaborated enum specifier cannot be declared as a friend}}48                         // expected-note@-2 {{remove 'enum class' to befriend an enum}}49  };50}51 52struct S2 {53  void f(int i);54  void g(int i);55};56 57void S2::f(int i) {58  (void)[&, &i, &i]{}; // expected-error 2{{'&' cannot precede a capture when the capture default is '&'}}59  (void)[i, i]{ }; // expected-error{{'i' can appear only once in a capture list}}60  (void)[&, i, i]{ }; // expected-error{{'i' can appear only once in a capture list}}61  (void)[] mutable {};62  (void)[]->int{ return 0; };63#if __cplusplus <= 202002L64  // expected-warning@-3{{is a C++23 extension}}65  // expected-warning@-3{{is a C++23 extension}}66#endif67 68  delete []() { return new int; }(); // expected-error{{'[]' after delete interpreted as 'delete[]'}}69  delete [] { return new int; }(); // expected-error{{'[]' after delete interpreted as 'delete[]'}}70}71 72#define bar "bar"73const char *p = "foo"bar; // expected-error {{requires a space between}}74#define ord - '0'75int k = '4'ord; // expected-error {{requires a space between}}76 77void operator"x"_y(char); // expected-error {{must be '""'}}78void operator L""_z(char); // expected-error {{encoding prefix}}79void operator "x" "y" U"z" ""_whoops "z" "y"(char); // expected-error {{must be '""'}}80 81void f() {82  'b'_y;83  'c'_z;84  'd'_whoops;85}86 87template<typename ...Ts> struct MisplacedEllipsis {88  int a(Ts ...(x)); // expected-error {{'...' must immediately precede declared identifier}}89  int b(Ts ...&x); // expected-error {{'...' must immediately precede declared identifier}}90  int c(Ts ...&); // expected-error {{'...' must be innermost component of anonymous pack declaration}}91  int d(Ts ...(...&...)); // expected-error 2{{'...' must be innermost component of anonymous pack declaration}}92  int e(Ts ...*[]); // expected-error {{'...' must be innermost component of anonymous pack declaration}}93  int f(Ts ...(...*)()); // expected-error 2{{'...' must be innermost component of anonymous pack declaration}}94  int g(Ts ...()); // ok95};96namespace TestMisplacedEllipsisRecovery {97  MisplacedEllipsis<int, char> me;98  int i; char k;99  int *ip; char *kp;100  int ifn(); char kfn();101  int a = me.a(i, k);102  int b = me.b(i, k);103  int c = me.c(i, k);104  int d = me.d(i, k);105  int e = me.e(&ip, &kp);106  int f = me.f(ifn, kfn);107  int g = me.g(ifn, kfn);108}109 110template<template<typename> ...Foo, // expected-error {{template template parameter requires 'class' after the parameter list}}111         template<template<template<typename>>>> // expected-error 3 {{template template parameter requires 'class' after the parameter list}}112void func();113 114template<int *ip> struct IP { }; // expected-note{{declared here}}115IP<0> ip0; // expected-error{{null non-type template argument must be cast to template parameter type 'int *'}}116 117namespace MissingSemi {118  struct a // expected-error {{expected ';' after struct}}119  struct b // expected-error {{expected ';' after struct}}120  enum x : int { x1, x2, x3 } // expected-error {{expected ';' after enum}}121  struct c // expected-error {{expected ';' after struct}}122  enum x : int // expected-error {{expected ';' after enum}}123  // FIXME: The following gives a poor diagnostic (we parse the 'int' and the124  // 'struct' as part of the same enum-base.125  //   enum x : int126  //   struct y127  namespace N {128    struct d // expected-error {{expected ';' after struct}}129  }130}131 132namespace NonStaticConstexpr {133  struct foo {134    constexpr int i; // expected-error {{non-static data member cannot be constexpr; did you intend to make it const?}}135    constexpr int j = 7; // expected-error {{non-static data member cannot be constexpr; did you intend to make it static?}}136    constexpr const int k; // expected-error {{non-static data member cannot be constexpr; did you intend to make it const?}}137    foo() : i(3), k(4) {138    }139    static int get_j() {140      return j;141    }142  };143}144 145int RegisterVariable() {146  register int n; // expected-warning {{'register' storage class specifier is deprecated}}147  return n;148}149 150namespace MisplacedParameterPack {151  template <typename Args...> // expected-error {{'...' must immediately precede declared identifier}}152  void misplacedEllipsisInTypeParameter(Args...);153 154  template <typename... Args...> // expected-error {{'...' must immediately precede declared identifier}}155  void redundantEllipsisInTypeParameter(Args...);156 157  template <template <typename> class Args...> // expected-error {{'...' must immediately precede declared identifier}}158  void misplacedEllipsisInTemplateTypeParameter(Args<int>...);159 160  template <template <typename> class... Args...> // expected-error {{'...' must immediately precede declared identifier}}161  void redundantEllipsisInTemplateTypeParameter(Args<int>...);162 163  template <int N...> // expected-error {{'...' must immediately precede declared identifier}}164  void misplacedEllipsisInNonTypeTemplateParameter();165 166  template <int... N...> // expected-error {{'...' must immediately precede declared identifier}}167  void redundantEllipsisInNonTypeTemplateParameter();168}169 170namespace MisplacedDeclAndRefSpecAfterVirtSpec {171  struct B {172    virtual void f();173    virtual void f() volatile const;174  };175  struct D : B {176    virtual void f() override;177    virtual void f() override final const volatile; // expected-error {{'const' qualifier may not appear after the virtual specifier 'final'}} expected-error {{'volatile' qualifier may not appear after the virtual specifier 'final'}}178  };179  struct B2 {180    virtual void f() &;181    virtual void f() volatile const &&;182  };183  struct D2 : B2 {184    virtual void f() override &; // expected-error {{'&' qualifier may not appear after the virtual specifier 'override'}}185    virtual void f() override final const volatile &&; //  expected-error {{'const' qualifier may not appear after the virtual specifier 'final'}} expected-error {{'volatile' qualifier may not appear after the virtual specifier 'final'}} expected-error {{'&&' qualifier may not appear after the virtual specifier 'final'}}186  };187}188