130f2a74f882adcadb8060d914684f65a401d87baRichard Smith// RUN: %clang_cc1 -verify -std=c++11 -Wno-anonymous-pack-parens %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" _y(char); // expected-error {{must be '""'}} 7033762775706e81c17ca774102ceda36049ecc593Richard Smithvoid operator L"" _z(char); // expected-error {{encoding prefix}} 7133762775706e81c17ca774102ceda36049ecc593Richard Smithvoid operator "x" "y" U"z" ""_whoops "z" "y"(char); // expected-error {{must be '""'}} 7233762775706e81c17ca774102ceda36049ecc593Richard Smith 7333762775706e81c17ca774102ceda36049ecc593Richard Smithvoid f() { 7433762775706e81c17ca774102ceda36049ecc593Richard Smith 'b'_y; 7533762775706e81c17ca774102ceda36049ecc593Richard Smith 'c'_z; 7633762775706e81c17ca774102ceda36049ecc593Richard Smith 'd'_whoops; 7733762775706e81c17ca774102ceda36049ecc593Richard Smith} 789988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith 799988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smithtemplate<typename ...Ts> struct MisplacedEllipsis { 809988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith int a(Ts ...(x)); // expected-error {{'...' must immediately precede declared identifier}} 819988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith int b(Ts ...&x); // expected-error {{'...' must immediately precede declared identifier}} 829988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith int c(Ts ...&); // expected-error {{'...' must be innermost component of anonymous pack declaration}} 839988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith int d(Ts ...(...&...)); // expected-error 2{{'...' must be innermost component of anonymous pack declaration}} 849988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith int e(Ts ...*[]); // expected-error {{'...' must be innermost component of anonymous pack declaration}} 859988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith int f(Ts ...(...*)()); // expected-error 2{{'...' must be innermost component of anonymous pack declaration}} 869988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith int g(Ts ...()); // ok 879988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith}; 889988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smithnamespace TestMisplacedEllipsisRecovery { 899988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith MisplacedEllipsis<int, char> me; 909988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith int i; char k; 919988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith int *ip; char *kp; 929988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith int ifn(); char kfn(); 939988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith int a = me.a(i, k); 949988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith int b = me.b(i, k); 959988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith int c = me.c(i, k); 969988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith int d = me.d(i, k); 979988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith int e = me.e(&ip, &kp); 989988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith int f = me.f(ifn, kfn); 999988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith int g = me.g(ifn, kfn); 1009988f28fe7a6c19239a7426fea1ab23f9a8aac9cRichard Smith} 1019df1b963a69dc85a271b3791267e994485e0bfe1David Blaikie 102673720d8cfbc8c9d08faec2817f1e1452e4ecc2eDavid Blaikietemplate<template<typename> ...Foo, // expected-error {{template template parameter requires 'class' after the parameter list}} 103673720d8cfbc8c9d08faec2817f1e1452e4ecc2eDavid Blaikie template<template<template<typename>>>> // expected-error 3 {{template template parameter requires 'class' after the parameter list}} 1049df1b963a69dc85a271b3791267e994485e0bfe1David Blaikievoid func(); 105d2008e2c80d6c9282044ec873a937a17a0f33579Douglas Gregor 106d2008e2c80d6c9282044ec873a937a17a0f33579Douglas Gregortemplate<int *ip> struct IP { }; // expected-note{{declared here}} 107d2008e2c80d6c9282044ec873a937a17a0f33579Douglas GregorIP<0> ip0; // expected-error{{null non-type template argument must be cast to template parameter type 'int *'}} 108d2008e2c80d6c9282044ec873a937a17a0f33579Douglas Gregor 109c9f351700721150a985f21844fbfec55b04e861dRichard Smithnamespace MissingSemi { 110c9f351700721150a985f21844fbfec55b04e861dRichard Smith struct a // expected-error {{expected ';' after struct}} 111c9f351700721150a985f21844fbfec55b04e861dRichard Smith struct b // expected-error {{expected ';' after struct}} 112c9f351700721150a985f21844fbfec55b04e861dRichard Smith enum x : int { x1, x2, x3 } // expected-error {{expected ';' after enum}} 113c9f351700721150a985f21844fbfec55b04e861dRichard Smith struct c // expected-error {{expected ';' after struct}} 114c9f351700721150a985f21844fbfec55b04e861dRichard Smith enum x : int // expected-error {{expected ';' after enum}} 115c9f351700721150a985f21844fbfec55b04e861dRichard Smith // FIXME: The following gives a poor diagnostic (we parse the 'int' and the 116c9f351700721150a985f21844fbfec55b04e861dRichard Smith // 'struct' as part of the same enum-base. 117c9f351700721150a985f21844fbfec55b04e861dRichard Smith // enum x : int 118c9f351700721150a985f21844fbfec55b04e861dRichard Smith // struct y 119c9f351700721150a985f21844fbfec55b04e861dRichard Smith namespace N { 120c9f351700721150a985f21844fbfec55b04e861dRichard Smith struct d // expected-error {{expected ';' after struct}} 121c9f351700721150a985f21844fbfec55b04e861dRichard Smith } 122c9f351700721150a985f21844fbfec55b04e861dRichard Smith} 1231d87fbaeea4a9fbbd73b3a53641f59f1673098e5David Blaikie 1241d87fbaeea4a9fbbd73b3a53641f59f1673098e5David Blaikienamespace NonStaticConstexpr { 1251d87fbaeea4a9fbbd73b3a53641f59f1673098e5David Blaikie struct foo { 1261d87fbaeea4a9fbbd73b3a53641f59f1673098e5David Blaikie constexpr int i; // expected-error {{non-static data member cannot be constexpr; did you intend to make it const?}} 1271d87fbaeea4a9fbbd73b3a53641f59f1673098e5David Blaikie constexpr int j = 7; // expected-error {{non-static data member cannot be constexpr; did you intend to make it static?}} 1286bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines constexpr const int k; // expected-error {{non-static data member cannot be constexpr; did you intend to make it const?}} 1296bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines foo() : i(3), k(4) { 1301d87fbaeea4a9fbbd73b3a53641f59f1673098e5David Blaikie } 1311d87fbaeea4a9fbbd73b3a53641f59f1673098e5David Blaikie static int get_j() { 1321d87fbaeea4a9fbbd73b3a53641f59f1673098e5David Blaikie return j; 1331d87fbaeea4a9fbbd73b3a53641f59f1673098e5David Blaikie } 1341d87fbaeea4a9fbbd73b3a53641f59f1673098e5David Blaikie }; 1351d87fbaeea4a9fbbd73b3a53641f59f1673098e5David Blaikie} 13679f4bb7aad1b7c53f8a3bc43d89de0efdef8286dRichard Smith 13779f4bb7aad1b7c53f8a3bc43d89de0efdef8286dRichard Smithint RegisterVariable() { 13879f4bb7aad1b7c53f8a3bc43d89de0efdef8286dRichard Smith register int n; // expected-warning {{'register' storage class specifier is deprecated}} 13979f4bb7aad1b7c53f8a3bc43d89de0efdef8286dRichard Smith return n; 14079f4bb7aad1b7c53f8a3bc43d89de0efdef8286dRichard Smith} 141c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 142c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hinesnamespace MisplacedParameterPack { 143c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines template <typename Args...> // expected-error {{'...' must immediately precede declared identifier}} 144c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines void misplacedEllipsisInTypeParameter(Args...); 145c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 146c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines template <typename... Args...> // expected-error {{'...' must immediately precede declared identifier}} 147c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines void redundantEllipsisInTypeParameter(Args...); 148c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 149c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines template <template <typename> class Args...> // expected-error {{'...' must immediately precede declared identifier}} 150c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines void misplacedEllipsisInTemplateTypeParameter(Args<int>...); 151c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 152c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines template <template <typename> class... Args...> // expected-error {{'...' must immediately precede declared identifier}} 153c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines void redundantEllipsisInTemplateTypeParameter(Args<int>...); 154c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 155c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines template <int N...> // expected-error {{'...' must immediately precede declared identifier}} 156c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines void misplacedEllipsisInNonTypeTemplateParameter(); 157c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 158c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines template <int... N...> // expected-error {{'...' must immediately precede declared identifier}} 159c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines void redundantEllipsisInNonTypeTemplateParameter(); 160c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines} 1613ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar 1623ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainarnamespace MisplacedDeclAndRefSpecAfterVirtSpec { 1633ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar struct B { 1643ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar virtual void f(); 1653ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar virtual void f() volatile const; 1663ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar }; 1673ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar struct D : B { 1683ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar virtual void f() override; 1693ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar 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'}} 1703ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar }; 1713ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar struct B2 { 1723ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar virtual void f() &; 1733ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar virtual void f() volatile const &&; 1743ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar }; 1753ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar struct D2 : B2 { 1763ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar virtual void f() override &; // expected-error {{'&' qualifier may not appear after the virtual specifier 'override'}} 1773ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar 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'}} 1783ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar }; 1793ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar} 180