diff options
author | Tim Northover <tnorthover@apple.com> | 2017-08-08 22:03:54 +0000 |
---|---|---|
committer | Tim Northover <tnorthover@apple.com> | 2017-08-08 22:03:54 +0000 |
commit | 8fbb4c40b30606dbfe347edc985628920153f75d (patch) | |
tree | 3071c18e02eb55b13a490da8dd4411771845578d /clang | |
parent | d36945bf3a67fabfb5e28726deaede4295dcc574 (diff) | |
download | bcm5719-llvm-8fbb4c40b30606dbfe347edc985628920153f75d.tar.gz bcm5719-llvm-8fbb4c40b30606dbfe347edc985628920153f75d.zip |
Lexer: always allow imaginary constants in GNU mode.
llvm-svn: 310423
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Lex/LiteralSupport.cpp | 2 | ||||
-rw-r--r-- | clang/test/Lexer/imaginary-constants.cpp | 25 | ||||
-rw-r--r-- | clang/test/SemaCXX/constexpr-printing.cpp | 2 | ||||
-rw-r--r-- | clang/unittests/AST/DeclTest.cpp | 2 |
4 files changed, 28 insertions, 3 deletions
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp index a598a467816..52b259edce8 100644 --- a/clang/lib/Lex/LiteralSupport.cpp +++ b/clang/lib/Lex/LiteralSupport.cpp @@ -659,7 +659,7 @@ NumericLiteralParser::NumericLiteralParser(StringRef TokSpelling, } } // "i", "if", and "il" are user-defined suffixes in C++1y. - if (*s == 'i' && PP.getLangOpts().CPlusPlus14) + if (*s == 'i' && !PP.getLangOpts().GNUMode) break; // fall through. case 'j': diff --git a/clang/test/Lexer/imaginary-constants.cpp b/clang/test/Lexer/imaginary-constants.cpp new file mode 100644 index 00000000000..3a176be54a1 --- /dev/null +++ b/clang/test/Lexer/imaginary-constants.cpp @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s -std=gnu++98 -DHAVE_IMAGINARY=1 +// RUN: %clang_cc1 -fsyntax-only -verify %s -std=gnu++11 -DHAVE_IMAGINARY=1 +// RUN: %clang_cc1 -fsyntax-only -verify %s -std=gnu++14 -DHAVE_IMAGINARY=1 +// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++98 -DHAVE_IMAGINARY=0 +// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -DHAVE_IMAGINARY=0 +// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++14 -DHAVE_IMAGINARY=0 -DCXX14=1 + +// Imaginary constants are a GNU extension that became problematic when C++14 +// defined its own versions. Until then they're supported even in +// standards-compliant mode. +#if HAVE_IMAGINARY +// expected-no-diagnostics +#elif CXX14 +// expected-error@+9 {{no matching literal operator for call to 'operator""i' with argument of type 'unsigned long long' or 'const char *', and no matching literal operator template}} +// expected-error@+9 {{no matching literal operator for call to 'operator""il' with argument of type 'unsigned long long' or 'const char *', and no matching literal operator template}} +// expected-error@+9 {{invalid suffix 'ill' on integer constant}} +#else +// expected-error@+5 {{invalid suffix 'i' on integer constant}} +// expected-error@+5 {{invalid suffix 'il' on integer constant}} +// expected-error@+7 {{invalid suffix 'ill' on integer constant}} +#endif + +_Complex int val1 = 2i; +_Complex long val2 = 2il; +_Complex long long val3 = 2ill; diff --git a/clang/test/SemaCXX/constexpr-printing.cpp b/clang/test/SemaCXX/constexpr-printing.cpp index 7f6a9c6a82f..3112fdeb355 100644 --- a/clang/test/SemaCXX/constexpr-printing.cpp +++ b/clang/test/SemaCXX/constexpr-printing.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -verify -triple x86_64-linux-gnu +// RUN: %clang_cc1 %s -std=gnu++11 -fsyntax-only -verify -triple x86_64-linux-gnu struct S; constexpr int extract(const S &s); diff --git a/clang/unittests/AST/DeclTest.cpp b/clang/unittests/AST/DeclTest.cpp index 87aeef47c61..f06f21a55dc 100644 --- a/clang/unittests/AST/DeclTest.cpp +++ b/clang/unittests/AST/DeclTest.cpp @@ -26,7 +26,7 @@ TEST(Decl, CleansUpAPValues) { // This is a regression test for a memory leak in APValues for structs that // allocate memory. This test only fails if run under valgrind with full leak // checking enabled. - std::vector<std::string> Args(1, "-std=c++11"); + std::vector<std::string> Args(1, "-std=gnu++11"); Args.push_back("-fno-ms-extensions"); ASSERT_TRUE(runToolOnCodeWithArgs( Factory->create(), |