Index: include/clang/Basic/LangOptions.def =================================================================== --- include/clang/Basic/LangOptions.def +++ include/clang/Basic/LangOptions.def @@ -90,6 +90,7 @@ LANGOPT(CPlusPlus11 , 1, 0, "C++11") LANGOPT(CPlusPlus14 , 1, 0, "C++14") LANGOPT(CPlusPlus1z , 1, 0, "C++1z") +LANGOPT(CPlusPlus2a , 1, 0, "C++2a") LANGOPT(ObjC1 , 1, 0, "Objective-C 1") LANGOPT(ObjC2 , 1, 0, "Objective-C 2") BENIGN_LANGOPT(ObjCDefaultSynthProperties , 1, 0, Index: include/clang/Frontend/LangStandard.h =================================================================== --- include/clang/Frontend/LangStandard.h +++ include/clang/Frontend/LangStandard.h @@ -26,11 +26,12 @@ CPlusPlus11 = (1 << 4), CPlusPlus14 = (1 << 5), CPlusPlus1z = (1 << 6), - Digraphs = (1 << 7), - GNUMode = (1 << 8), - HexFloat = (1 << 9), - ImplicitInt = (1 << 10), - OpenCL = (1 << 11) + CPlusPlus2a = (1 << 7), + Digraphs = (1 << 8), + GNUMode = (1 << 9), + HexFloat = (1 << 10), + ImplicitInt = (1 << 11), + OpenCL = (1 << 12) }; } @@ -81,6 +82,10 @@ /// isCPlusPlus1z - Language is a C++17 variant (or later). bool isCPlusPlus1z() const { return Flags & frontend::CPlusPlus1z; } + /// isCPlusPlus2a - Language is a post-C++17 variant (or later). + bool isCPlusPlus2a() const { return Flags & frontend::CPlusPlus2a; } + + /// hasDigraphs - Language supports digraphs. bool hasDigraphs() const { return Flags & frontend::Digraphs; } Index: include/clang/Frontend/LangStandards.def =================================================================== --- include/clang/Frontend/LangStandards.def +++ include/clang/Frontend/LangStandards.def @@ -119,6 +119,16 @@ LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus1z | Digraphs | HexFloat | GNUMode) +LANGSTANDARD(cxx2a, "c++2a", + CXX, "Working draft for ISO C++ 2020", + LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus1z | + CPlusPlus2a | Digraphs | HexFloat) + +LANGSTANDARD(gnucxx2a, "gnu++2a", + CXX, "Working draft for ISO C++ 2020 with GNU extensions", + LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus1z | + CPlusPlus2a | Digraphs | HexFloat | GNUMode) + // OpenCL LANGSTANDARD(opencl10, "cl1.0", OpenCL, "OpenCL 1.0", Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -1683,6 +1683,7 @@ Opts.CPlusPlus11 = Std.isCPlusPlus11(); Opts.CPlusPlus14 = Std.isCPlusPlus14(); Opts.CPlusPlus1z = Std.isCPlusPlus1z(); + Opts.CPlusPlus2a = Std.isCPlusPlus2a(); Opts.Digraphs = Std.hasDigraphs(); Opts.GNUMode = Std.isGNUMode(); Opts.GNUInline = !Opts.C99 && !Opts.CPlusPlus; Index: lib/Frontend/InitPreprocessor.cpp =================================================================== --- lib/Frontend/InitPreprocessor.cpp +++ lib/Frontend/InitPreprocessor.cpp @@ -374,10 +374,13 @@ else if (!LangOpts.GNUMode && LangOpts.Digraphs) Builder.defineMacro("__STDC_VERSION__", "199409L"); } else { + // FIXME: Use correct value for C++20 + if (LangOpts.CPlusPlus2a) + Builder.defineMacro("__cplusplus", "201707L"); // C++17 [cpp.predefined]p1: // The name __cplusplus is defined to the value 201703L when compiling a // C++ translation unit. - if (LangOpts.CPlusPlus1z) + else if (LangOpts.CPlusPlus1z) Builder.defineMacro("__cplusplus", "201703L"); // C++1y [cpp.predefined]p1: // The name __cplusplus is defined to the value 201402L when compiling a Index: test/Driver/std.cpp =================================================================== --- test/Driver/std.cpp +++ test/Driver/std.cpp @@ -9,7 +9,10 @@ // RUN: not %clang -std=gnu++1y %s -fsyntax-only 2>&1 | FileCheck -check-prefix=GNUXX1Y %s // RUN: not %clang -std=c++1z %s -fsyntax-only 2>&1 | FileCheck -check-prefix=CXX1Z %s // RUN: not %clang -std=gnu++1z %s -fsyntax-only 2>&1 | FileCheck -check-prefix=GNUXX1Z %s +// RUN: not %clang -std=c++2a %s -fsyntax-only 2>&1 | FileCheck -check-prefix=CXX2A %s +// RUN: not %clang -std=gnu++2a %s -fsyntax-only 2>&1 | FileCheck -check-prefix=GNUXX2A %s + void f(int n) { typeof(n)(); decltype(n)(); @@ -38,3 +41,10 @@ // GNUXX1Z-NOT: undeclared identifier 'typeof' // GNUXX1Z-NOT: undeclared identifier 'decltype' + +// CXX2A: undeclared identifier 'typeof' +// CXX2A-NOT: undeclared identifier 'decltype' + +// GNUXX2A-NOT: undeclared identifier 'typeof' +// GNUXX2A-NOT: undeclared identifier 'decltype' + Index: test/Driver/unknown-std.cpp =================================================================== --- test/Driver/unknown-std.cpp +++ test/Driver/unknown-std.cpp @@ -15,6 +15,8 @@ // CHECK-NEXT: note: use 'gnu++14' for 'ISO C++ 2014 with amendments and GNU extensions' standard // CHECK-NEXT: note: use 'c++1z' for 'Working draft for ISO C++ 2017' standard // CHECK-NEXT: note: use 'gnu++1z' for 'Working draft for ISO C++ 2017 with GNU extensions' standard +// CHECK-NEXT: note: use 'c++2a' for 'Working draft for ISO C++ 2020' standard +// CHECK-NEXT: note: use 'gnu++2a' for 'Working draft for ISO C++ 2020 with GNU extensions' standard // CUDA-NEXT: note: use 'cuda' for 'NVIDIA CUDA(tm)' standard // Make sure that no other output is present. Index: test/Preprocessor/init.c =================================================================== --- test/Preprocessor/init.c +++ test/Preprocessor/init.c @@ -9,6 +9,15 @@ // BLOCKS:#define __block __attribute__((__blocks__(byref))) // // +// RUN: %clang_cc1 -x c++ -std=c++2a -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX2A %s +// +// CXX2A:#define __GNUG__ {{.*}} +// CXX2A:#define __GXX_EXPERIMENTAL_CXX0X__ 1 +// CXX2A:#define __GXX_RTTI 1 +// CXX2A:#define __GXX_WEAK__ 1 +// CXX2A:#define __cplusplus 201707L +// CXX2A:#define __private_extern__ extern +// // RUN: %clang_cc1 -x c++ -std=c++1z -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX1Z %s // // CXX1Z:#define __GNUG__ {{.*}} @@ -110,7 +119,14 @@ // RUN: %clang_cc1 -ffreestanding -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix FREESTANDING %s // FREESTANDING:#define __STDC_HOSTED__ 0 // +// RUN: %clang_cc1 -x c++ -std=gnu++2a -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX2A %s // +// GXX2A:#define __GNUG__ {{.*}} +// GXX2A:#define __GXX_WEAK__ 1 +// GXX2A:#define __cplusplus 201707L +// GXX2A:#define __private_extern__ extern +// +// // RUN: %clang_cc1 -x c++ -std=gnu++1z -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX1Z %s // // GXX1Z:#define __GNUG__ {{.*}}