cxx98-compat.cpp revision 841804baff6ea8ba1904a2ba81265aae1479e882
1// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wc++98-compat -verify %s 2 3template<typename ...T> // expected-warning {{variadic templates are incompatible with C++98}} 4class Variadic1 {}; 5 6template<template<typename> class ...T> // expected-warning {{variadic templates are incompatible with C++98}} 7class Variadic2 {}; 8 9template<int ...I> // expected-warning {{variadic templates are incompatible with C++98}} 10class Variadic3 {}; 11 12int alignas(8) with_alignas; // expected-warning {{'alignas' is incompatible with C++98}} 13int with_attribute [[ ]]; // expected-warning {{attributes are incompatible with C++98}} 14 15void Literals() { 16 (void)u8"str"; // expected-warning {{unicode literals are incompatible with C++98}} 17 (void)u"str"; // expected-warning {{unicode literals are incompatible with C++98}} 18 (void)U"str"; // expected-warning {{unicode literals are incompatible with C++98}} 19 (void)u'x'; // expected-warning {{unicode literals are incompatible with C++98}} 20 (void)U'x'; // expected-warning {{unicode literals are incompatible with C++98}} 21 22 (void)u8R"X(str)X"; // expected-warning {{raw string literals are incompatible with C++98}} 23 (void)uR"X(str)X"; // expected-warning {{raw string literals are incompatible with C++98}} 24 (void)UR"X(str)X"; // expected-warning {{raw string literals are incompatible with C++98}} 25 (void)R"X(str)X"; // expected-warning {{raw string literals are incompatible with C++98}} 26 (void)LR"X(str)X"; // expected-warning {{raw string literals are incompatible with C++98}} 27} 28 29template<typename T> struct S {}; 30namespace TemplateParsing { 31 S<::S<void> > s; // expected-warning {{'<::' is treated as digraph '<:' (aka '[') followed by ':' in C++98}} 32 S< ::S<void>> t; // expected-warning {{consecutive right angle brackets are incompatible with C++98 (use '> >')}} 33} 34 35void Lambda() { 36 []{}; // expected-warning {{lambda expressions are incompatible with C++98}} 37} 38 39int InitList() { 40 (void)new int {}; // expected-warning {{generalized initializer lists are incompatible with C++98}} 41 (void)int{}; // expected-warning {{generalized initializer lists are incompatible with C++98}} 42 int x {}; // expected-warning {{generalized initializer lists are incompatible with C++98}} 43 return {}; // expected-warning {{generalized initializer lists are incompatible with C++98}} 44} 45 46int operator""_hello(const char *); // expected-warning {{literal operators are incompatible with C++98}} 47 48enum EnumFixed : int { // expected-warning {{enumeration types with a fixed underlying type are incompatible with C++98}} 49}; 50 51enum class EnumScoped { // expected-warning {{scoped enumerations are incompatible with C++98}} 52}; 53 54void Deleted() = delete; // expected-warning {{deleted function definitions are incompatible with C++98}} 55struct Defaulted { 56 Defaulted() = default; // expected-warning {{defaulted function definitions are incompatible with C++98}} 57}; 58 59int &&RvalueReference = 0; // expected-warning {{rvalue references are incompatible with C++98}} 60struct RefQualifier { 61 void f() &; // expected-warning {{reference qualifiers on functions are incompatible with C++98}} 62}; 63 64auto f() -> int; // expected-warning {{trailing return types are incompatible with C++98}} 65 66void RangeFor() { 67 int xs[] = {1, 2, 3}; 68 for (int &a : xs) { // expected-warning {{range-based for loop is incompatible with C++98}} 69 } 70} 71 72struct InClassInit { 73 int n = 0; // expected-warning {{in-class initialization of non-static data members is incompatible with C++98}} 74}; 75 76struct OverrideControlBase { 77 virtual void f(); 78 virtual void g(); 79}; 80struct OverrideControl final : OverrideControlBase { // expected-warning {{'final' keyword is incompatible with C++98}} 81 virtual void f() override; // expected-warning {{'override' keyword is incompatible with C++98}} 82 virtual void g() final; // expected-warning {{'final' keyword is incompatible with C++98}} 83}; 84 85using AliasDecl = int; // expected-warning {{alias declarations are incompatible with C++98}} 86template<typename T> using AliasTemplate = T; // expected-warning {{alias declarations are incompatible with C++98}} 87 88inline namespace N { // expected-warning {{inline namespaces are incompatible with C++98}} 89} 90 91auto auto_deduction = 0; // expected-warning {{'auto' type specifier is incompatible with C++98}} 92int *p = new auto(0); // expected-warning {{'auto' type specifier is incompatible with C++98}} 93 94const int align_of = alignof(int); // expected-warning {{alignof expressions are incompatible with C++98}} 95char16_t c16 = 0; // expected-warning {{'char16_t' type specifier is incompatible with C++98}} 96char32_t c32 = 0; // expected-warning {{'char32_t' type specifier is incompatible with C++98}} 97constexpr int const_expr = 0; // expected-warning {{'constexpr' specifier is incompatible with C++98}} 98decltype(const_expr) decl_type = 0; // expected-warning {{'decltype' type specifier is incompatible with C++98}} 99void no_except() noexcept; // expected-warning {{noexcept specifications are incompatible with C++98}} 100bool no_except_expr = noexcept(1 + 1); // expected-warning {{noexcept expressions are incompatible with C++98}} 101void *null = nullptr; // expected-warning {{'nullptr' is incompatible with C++98}} 102static_assert(true, "!"); // expected-warning {{static_assert declarations are incompatible with C++98}} 103