1762bb9d0ad20320b9f97a841dce57ba5e8e48b07Richard Smith// RUN: %clang_cc1 -verify -std=c++11 %s
2ba5f6eced29937e4e4851a2c0980744768413d66Nick Lewycky// RUN: cp %s %t
3762bb9d0ad20320b9f97a841dce57ba5e8e48b07Richard Smith// RUN: not %clang_cc1 -x c++ -std=c++11 -fixit %t
4762bb9d0ad20320b9f97a841dce57ba5e8e48b07Richard Smith// RUN: %clang_cc1 -Wall -pedantic -x c++ -std=c++11 %t
584fb9c0be621c9e4ca4e56f67dae2a0bb6e44821Douglas Gregor
684fb9c0be621c9e4ca4e56f67dae2a0bb6e44821Douglas Gregor/* This is a test of the various code modification hints that only
784fb9c0be621c9e4ca4e56f67dae2a0bb6e44821Douglas Gregor   apply in C++0x. */
8ba5f6eced29937e4e4851a2c0980744768413d66Nick Lewyckystruct A {
984fb9c0be621c9e4ca4e56f67dae2a0bb6e44821Douglas Gregor  explicit operator int(); // expected-note{{conversion to integral type}}
1084fb9c0be621c9e4ca4e56f67dae2a0bb6e44821Douglas Gregor};
1184fb9c0be621c9e4ca4e56f67dae2a0bb6e44821Douglas Gregor
12ba5f6eced29937e4e4851a2c0980744768413d66Nick Lewyckyvoid x() {
1384fb9c0be621c9e4ca4e56f67dae2a0bb6e44821Douglas Gregor  switch(A()) { // expected-error{{explicit conversion to}}
1484fb9c0be621c9e4ca4e56f67dae2a0bb6e44821Douglas Gregor  }
1584fb9c0be621c9e4ca4e56f67dae2a0bb6e44821Douglas Gregor}
1684fb9c0be621c9e4ca4e56f67dae2a0bb6e44821Douglas Gregor
17162e1c1b487352434552147967c3dd296ebee2f7Richard Smithusing ::T = void; // expected-error {{name defined in alias declaration must be an identifier}}
18162e1c1b487352434552147967c3dd296ebee2f7Richard Smithusing typename U = void; // expected-error {{name defined in alias declaration must be an identifier}}
19162e1c1b487352434552147967c3dd296ebee2f7Richard Smithusing typename ::V = void; // expected-error {{name defined in alias declaration must be an identifier}}
20c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smith
210706df40064d4d7559b4304af79d519033414b84Richard Smithnamespace SemiCommaTypo {
220706df40064d4d7559b4304af79d519033414b84Richard Smith  int m {},
230706df40064d4d7559b4304af79d519033414b84Richard Smith  n [[]], // expected-error {{expected ';' at end of declaration}}
240706df40064d4d7559b4304af79d519033414b84Richard Smith  int o;
251c94c16317c1a35c1549e022958188eea2567089Richard Smith
261c94c16317c1a35c1549e022958188eea2567089Richard Smith  struct Base {
271c94c16317c1a35c1549e022958188eea2567089Richard Smith    virtual void f2(), f3();
281c94c16317c1a35c1549e022958188eea2567089Richard Smith  };
291c94c16317c1a35c1549e022958188eea2567089Richard Smith  struct MemberDeclarator : Base {
301c94c16317c1a35c1549e022958188eea2567089Richard Smith    int k : 4,
311c94c16317c1a35c1549e022958188eea2567089Richard Smith        //[[]] : 1, FIXME: test this once we support attributes here
321c94c16317c1a35c1549e022958188eea2567089Richard Smith        : 9, // expected-error {{expected ';' at end of declaration}}
331c94c16317c1a35c1549e022958188eea2567089Richard Smith    char c, // expected-error {{expected ';' at end of declaration}}
341c94c16317c1a35c1549e022958188eea2567089Richard Smith    typedef void F(), // expected-error {{expected ';' at end of declaration}}
351c94c16317c1a35c1549e022958188eea2567089Richard Smith    F f1,
361c94c16317c1a35c1549e022958188eea2567089Richard Smith      f2 final,
371c94c16317c1a35c1549e022958188eea2567089Richard Smith      f3 override, // expected-error {{expected ';' at end of declaration}}
381c94c16317c1a35c1549e022958188eea2567089Richard Smith  };
390706df40064d4d7559b4304af79d519033414b84Richard Smith}
40bdad7a2e21686296b78dac6190b78d11c996f6d7Richard Smith
41bdad7a2e21686296b78dac6190b78d11c996f6d7Richard Smithnamespace ScopedEnum {
42bdad7a2e21686296b78dac6190b78d11c996f6d7Richard Smith  enum class E { a };
43bdad7a2e21686296b78dac6190b78d11c996f6d7Richard Smith
44bdad7a2e21686296b78dac6190b78d11c996f6d7Richard Smith  enum class E b = E::a; // expected-error {{must use 'enum' not 'enum class'}}
45bdad7a2e21686296b78dac6190b78d11c996f6d7Richard Smith  struct S {
46bdad7a2e21686296b78dac6190b78d11c996f6d7Richard Smith    friend enum class E; // expected-error {{must use 'enum' not 'enum class'}}
47bdad7a2e21686296b78dac6190b78d11c996f6d7Richard Smith  };
48bdad7a2e21686296b78dac6190b78d11c996f6d7Richard Smith}
493ac109cd17151bb8ad3a40b0cbb0e1923cd6c4a0Douglas Gregor
503ac109cd17151bb8ad3a40b0cbb0e1923cd6c4a0Douglas Gregorstruct S2 {
513ac109cd17151bb8ad3a40b0cbb0e1923cd6c4a0Douglas Gregor  void f(int i);
523ac109cd17151bb8ad3a40b0cbb0e1923cd6c4a0Douglas Gregor  void g(int i);
533ac109cd17151bb8ad3a40b0cbb0e1923cd6c4a0Douglas Gregor};
543ac109cd17151bb8ad3a40b0cbb0e1923cd6c4a0Douglas Gregor
553ac109cd17151bb8ad3a40b0cbb0e1923cd6c4a0Douglas Gregorvoid S2::f(int i) {
563ac109cd17151bb8ad3a40b0cbb0e1923cd6c4a0Douglas Gregor  (void)[&, &i, &i]{}; // expected-error 2{{'&' cannot precede a capture when the capture default is '&'}}
573ac109cd17151bb8ad3a40b0cbb0e1923cd6c4a0Douglas Gregor  (void)[=, this]{ this->g(5); }; // expected-error{{'this' cannot be explicitly captured}}
583ac109cd17151bb8ad3a40b0cbb0e1923cd6c4a0Douglas Gregor  (void)[i, i]{ }; // expected-error{{'i' can appear only once in a capture list}}
593ac109cd17151bb8ad3a40b0cbb0e1923cd6c4a0Douglas Gregor  (void)[&, i, i]{ }; // expected-error{{'i' can appear only once in a capture list}}
6092dc03546ccfd417108c1fc74321091a82cbeeeeRichard Smith  (void)[] mutable { }; // expected-error{{lambda requires '()' before 'mutable'}}
6192dc03546ccfd417108c1fc74321091a82cbeeeeRichard Smith  (void)[] -> int { }; // expected-error{{lambda requires '()' before return type}}
623ac109cd17151bb8ad3a40b0cbb0e1923cd6c4a0Douglas Gregor}
632fb4ae36825ca3a0cbe7e845c5747062870066beRichard Smith
642fb4ae36825ca3a0cbe7e845c5747062870066beRichard Smith#define bar "bar"
652fb4ae36825ca3a0cbe7e845c5747062870066beRichard Smithconst char *p = "foo"bar; // expected-error {{requires a space between}}
662fb4ae36825ca3a0cbe7e845c5747062870066beRichard Smith#define ord - '0'
672fb4ae36825ca3a0cbe7e845c5747062870066beRichard Smithint k = '4'ord; // expected-error {{requires a space between}}
6833762775706e81c17ca774102ceda36049ecc593Richard Smith
6933762775706e81c17ca774102ceda36049ecc593Richard Smithvoid operator""_x(char); // expected-error {{requires a space}}
7033762775706e81c17ca774102ceda36049ecc593Richard Smithvoid operator"x" _y(char); // expected-error {{must be '""'}}
7133762775706e81c17ca774102ceda36049ecc593Richard Smithvoid operator L"" _z(char); // expected-error {{encoding prefix}}
7233762775706e81c17ca774102ceda36049ecc593Richard Smithvoid operator "x" "y" U"z" ""_whoops "z" "y"(char); // expected-error {{must be '""'}}
7333762775706e81c17ca774102ceda36049ecc593Richard Smith
7433762775706e81c17ca774102ceda36049ecc593Richard Smithvoid f() {
7533762775706e81c17ca774102ceda36049ecc593Richard Smith  'a'_x;
7633762775706e81c17ca774102ceda36049ecc593Richard Smith  'b'_y;
7733762775706e81c17ca774102ceda36049ecc593Richard Smith  'c'_z;
7833762775706e81c17ca774102ceda36049ecc593Richard Smith  'd'_whoops;
7933762775706e81c17ca774102ceda36049ecc593Richard Smith}
809988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith
819988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smithtemplate<typename ...Ts> struct MisplacedEllipsis {
829988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith  int a(Ts ...(x)); // expected-error {{'...' must immediately precede declared identifier}}
839988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith  int b(Ts ...&x); // expected-error {{'...' must immediately precede declared identifier}}
849988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith  int c(Ts ...&); // expected-error {{'...' must be innermost component of anonymous pack declaration}}
859988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith  int d(Ts ...(...&...)); // expected-error 2{{'...' must be innermost component of anonymous pack declaration}}
869988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith  int e(Ts ...*[]); // expected-error {{'...' must be innermost component of anonymous pack declaration}}
879988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith  int f(Ts ...(...*)()); // expected-error 2{{'...' must be innermost component of anonymous pack declaration}}
889988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith  int g(Ts ...()); // ok
899988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith};
909988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smithnamespace TestMisplacedEllipsisRecovery {
919988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith  MisplacedEllipsis<int, char> me;
929988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith  int i; char k;
939988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith  int *ip; char *kp;
949988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith  int ifn(); char kfn();
959988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith  int a = me.a(i, k);
969988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith  int b = me.b(i, k);
979988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith  int c = me.c(i, k);
989988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith  int d = me.d(i, k);
999988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith  int e = me.e(&ip, &kp);
1009988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith  int f = me.f(ifn, kfn);
1019988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith  int g = me.g(ifn, kfn);
1029988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith}
1039df1b963a69dc85a271b3791267e994485e0bfe1David Blaikie
104673720d8cfbc8c9d08faec2817f1e1452e4ecc2eDavid Blaikietemplate<template<typename> ...Foo, // expected-error {{template template parameter requires 'class' after the parameter list}}
105673720d8cfbc8c9d08faec2817f1e1452e4ecc2eDavid Blaikie         template<template<template<typename>>>> // expected-error 3 {{template template parameter requires 'class' after the parameter list}}
1069df1b963a69dc85a271b3791267e994485e0bfe1David Blaikievoid func();
107d2008e2c80d6c9282044ec873a937a17a0f33579Douglas Gregor
108d2008e2c80d6c9282044ec873a937a17a0f33579Douglas Gregortemplate<int *ip> struct IP { }; // expected-note{{declared here}}
109d2008e2c80d6c9282044ec873a937a17a0f33579Douglas GregorIP<0> ip0; // expected-error{{null non-type template argument must be cast to template parameter type 'int *'}}
110d2008e2c80d6c9282044ec873a937a17a0f33579Douglas Gregor
111c9f351700721150a985f21844fbfec55b04e861dRichard Smithnamespace MissingSemi {
112c9f351700721150a985f21844fbfec55b04e861dRichard Smith  struct a // expected-error {{expected ';' after struct}}
113c9f351700721150a985f21844fbfec55b04e861dRichard Smith  struct b // expected-error {{expected ';' after struct}}
114c9f351700721150a985f21844fbfec55b04e861dRichard Smith  enum x : int { x1, x2, x3 } // expected-error {{expected ';' after enum}}
115c9f351700721150a985f21844fbfec55b04e861dRichard Smith  struct c // expected-error {{expected ';' after struct}}
116c9f351700721150a985f21844fbfec55b04e861dRichard Smith  enum x : int // expected-error {{expected ';' after enum}}
117c9f351700721150a985f21844fbfec55b04e861dRichard Smith  // FIXME: The following gives a poor diagnostic (we parse the 'int' and the
118c9f351700721150a985f21844fbfec55b04e861dRichard Smith  // 'struct' as part of the same enum-base.
119c9f351700721150a985f21844fbfec55b04e861dRichard Smith  //   enum x : int
120c9f351700721150a985f21844fbfec55b04e861dRichard Smith  //   struct y
121c9f351700721150a985f21844fbfec55b04e861dRichard Smith  namespace N {
122c9f351700721150a985f21844fbfec55b04e861dRichard Smith    struct d // expected-error {{expected ';' after struct}}
123c9f351700721150a985f21844fbfec55b04e861dRichard Smith  }
124c9f351700721150a985f21844fbfec55b04e861dRichard Smith}
125