From a2ce7ac7a57b3839e3e5a0810fdfc90a73eed964 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 8 Oct 2015 00:17:59 +0000 Subject: [PATCH] When pretty-printing a C++11 literal operator, don't insert whitespace between the "" and the suffix; that breaks names such as 'operator""if'. For symmetry, also remove the space between the 'operator' and the '""'. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249641 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/DeclarationName.cpp | 2 +- lib/AST/StmtPrinter.cpp | 2 +- lib/Parse/ParseExprCXX.cpp | 2 +- test/CXX/lex/lex.literal/lex.ext/p12.cpp | 4 ++-- test/CXX/lex/lex.literal/lex.ext/p2.cpp | 22 ++++++++++---------- test/CXX/lex/lex.literal/lex.ext/p5.cpp | 2 +- test/CXX/lex/lex.literal/lex.ext/p7.cpp | 8 +++---- test/CXX/over/over.oper/over.literal/p2.cpp | 2 +- test/Lexer/hexfloat.cpp | 2 +- test/Parser/cxx11-user-defined-literals.cpp | 14 ++++++------- test/SemaCXX/cxx11-ast-print.cpp | 14 ++++++------- test/SemaCXX/cxx11-user-defined-literals.cpp | 10 ++++----- test/SemaCXX/literal-operators.cpp | 12 +++++++---- 13 files changed, 50 insertions(+), 46 deletions(-) diff --git a/lib/AST/DeclarationName.cpp b/lib/AST/DeclarationName.cpp index b7c2877200..b2f27275f4 100644 --- a/lib/AST/DeclarationName.cpp +++ b/lib/AST/DeclarationName.cpp @@ -182,7 +182,7 @@ raw_ostream &operator<<(raw_ostream &OS, DeclarationName N) { } case DeclarationName::CXXLiteralOperatorName: - return OS << "operator \"\" " << N.getCXXLiteralIdentifier()->getName(); + return OS << "operator\"\"" << N.getCXXLiteralIdentifier()->getName(); case DeclarationName::CXXConversionFunctionName: { OS << "operator "; diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index d0603478e6..bf155f5680 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -1727,7 +1727,7 @@ void StmtPrinter::VisitUserDefinedLiteral(UserDefinedLiteral *Node) { assert(Args); if (Args->size() != 1) { - OS << "operator \"\" " << Node->getUDSuffix()->getName(); + OS << "operator\"\"" << Node->getUDSuffix()->getName(); TemplateSpecializationType::PrintTemplateArgumentList( OS, Args->data(), Args->size(), Policy); OS << "()"; diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index 87f3809130..2bf4cba798 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -2289,7 +2289,7 @@ bool Parser::ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext, // This isn't a valid literal-operator-id, but we think we know // what the user meant. Tell them what they should have written. SmallString<32> Str; - Str += "\"\" "; + Str += "\"\""; Str += II->getName(); Diag(DiagLoc, DiagId) << FixItHint::CreateReplacement( SourceRange(TokLocs.front(), TokLocs.back()), Str); diff --git a/test/CXX/lex/lex.literal/lex.ext/p12.cpp b/test/CXX/lex/lex.literal/lex.ext/p12.cpp index dad4680939..34a2f5c678 100644 --- a/test/CXX/lex/lex.literal/lex.ext/p12.cpp +++ b/test/CXX/lex/lex.literal/lex.ext/p12.cpp @@ -15,7 +15,7 @@ void *operator""_x(const char*); // #2 void *a = 123_x; // ok, calls #2 int b = u8"\"тест 𐀀"_x; // ok, calls #1 int c = u8R"("тест 𐀀)"_x; // ok, calls #1 -int d = "test"_x; // expected-note {{in instantiation of function template specialization 'operator "" _x' requested here}} +int d = "test"_x; // expected-note {{in instantiation of function template specialization 'operator""_x' requested here}} int e = uR"("тест 𐀀)"_x; int f = UR"("тест 𐀀)"_x; -int g = UR"("тест_𐀀)"_x; // expected-note {{in instantiation of function template specialization 'operator "" _x' requested here}} +int g = UR"("тест_𐀀)"_x; // expected-note {{in instantiation of function template specialization 'operator""_x' requested here}} diff --git a/test/CXX/lex/lex.literal/lex.ext/p2.cpp b/test/CXX/lex/lex.literal/lex.ext/p2.cpp index 3f3f796e55..6942b68690 100644 --- a/test/CXX/lex/lex.literal/lex.ext/p2.cpp +++ b/test/CXX/lex/lex.literal/lex.ext/p2.cpp @@ -3,14 +3,14 @@ typedef decltype(sizeof(int)) size_t; // FIXME: These diagnostics should say 'size_t' instead of 'unsigned long' -int a = 123_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with argument of type 'unsigned long long' or 'const char *', and no matching literal operator template}} -int b = 4.2_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with argument of type 'long double' or 'const char *', and no matching literal operator template}} -int c = "foo"_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with arguments of types 'const char *' and 'unsigned}} -int d = L"foo"_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with arguments of types 'const wchar_t *' and 'unsigned}} -int e = u8"foo"_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with arguments of types 'const char *' and 'unsigned}} -int f = u"foo"_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with arguments of types 'const char16_t *' and 'unsigned}} -int g = U"foo"_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with arguments of types 'const char32_t *' and 'unsigned}} -int h = 'y'_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with argument of type 'char'}} -int i = L'y'_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with argument of type 'wchar_t'}} -int j = u'y'_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with argument of type 'char16_t'}} -int k = U'y'_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with argument of type 'char32_t'}} +int a = 123_x; // expected-error {{no matching literal operator for call to 'operator""_x' with argument of type 'unsigned long long' or 'const char *', and no matching literal operator template}} +int b = 4.2_x; // expected-error {{no matching literal operator for call to 'operator""_x' with argument of type 'long double' or 'const char *', and no matching literal operator template}} +int c = "foo"_x; // expected-error {{no matching literal operator for call to 'operator""_x' with arguments of types 'const char *' and 'unsigned}} +int d = L"foo"_x; // expected-error {{no matching literal operator for call to 'operator""_x' with arguments of types 'const wchar_t *' and 'unsigned}} +int e = u8"foo"_x; // expected-error {{no matching literal operator for call to 'operator""_x' with arguments of types 'const char *' and 'unsigned}} +int f = u"foo"_x; // expected-error {{no matching literal operator for call to 'operator""_x' with arguments of types 'const char16_t *' and 'unsigned}} +int g = U"foo"_x; // expected-error {{no matching literal operator for call to 'operator""_x' with arguments of types 'const char32_t *' and 'unsigned}} +int h = 'y'_x; // expected-error {{no matching literal operator for call to 'operator""_x' with argument of type 'char'}} +int i = L'y'_x; // expected-error {{no matching literal operator for call to 'operator""_x' with argument of type 'wchar_t'}} +int j = u'y'_x; // expected-error {{no matching literal operator for call to 'operator""_x' with argument of type 'char16_t'}} +int k = U'y'_x; // expected-error {{no matching literal operator for call to 'operator""_x' with argument of type 'char32_t'}} diff --git a/test/CXX/lex/lex.literal/lex.ext/p5.cpp b/test/CXX/lex/lex.literal/lex.ext/p5.cpp index d364a37c6c..a516168a69 100644 --- a/test/CXX/lex/lex.literal/lex.ext/p5.cpp +++ b/test/CXX/lex/lex.literal/lex.ext/p5.cpp @@ -6,7 +6,7 @@ int &operator "" _x1 (const char *); double &operator "" _x1 (const char *, size_t); double &i1 = "foo"_x1; double &i2 = u8"foo"_x1; -double &i3 = L"foo"_x1; // expected-error {{no matching literal operator for call to 'operator "" _x1' with arguments of types 'const wchar_t *' and 'unsigned long'}} +double &i3 = L"foo"_x1; // expected-error {{no matching literal operator for call to 'operator""_x1' with arguments of types 'const wchar_t *' and 'unsigned long'}} char &operator "" _x1(const wchar_t *, size_t); char &i4 = L"foo"_x1; // ok diff --git a/test/CXX/lex/lex.literal/lex.ext/p7.cpp b/test/CXX/lex/lex.literal/lex.ext/p7.cpp index be97f0cb92..0b40ecdc14 100644 --- a/test/CXX/lex/lex.literal/lex.ext/p7.cpp +++ b/test/CXX/lex/lex.literal/lex.ext/p7.cpp @@ -14,10 +14,10 @@ long double operator "" _w(long double); std::string operator "" _w(const char16_t*, size_t); unsigned operator "" _w(const char*); int main() { - auto v1 = 1.2_w; // calls operator "" _w(1.2L) - auto v2 = u"one"_w; // calls operator "" _w(u"one", 3) - auto v3 = 12_w; // calls operator "" _w("12") - "two"_w; // expected-error {{no matching literal operator for call to 'operator "" _w' with arguments of types 'const char *' and 'unsigned long'}} + auto v1 = 1.2_w; // calls operator""_w(1.2L) + auto v2 = u"one"_w; // calls operator""_w(u"one", 3) + auto v3 = 12_w; // calls operator""_w("12") + "two"_w; // expected-error {{no matching literal operator for call to 'operator""_w' with arguments of types 'const char *' and 'unsigned long'}} same_type test1; same_type test2; diff --git a/test/CXX/over/over.oper/over.literal/p2.cpp b/test/CXX/over/over.oper/over.literal/p2.cpp index 00466fb311..f3ebadd2b8 100644 --- a/test/CXX/over/over.oper/over.literal/p2.cpp +++ b/test/CXX/over/over.oper/over.literal/p2.cpp @@ -37,7 +37,7 @@ template void operator "" _h<'a', 'b', 'c', 'd'>(); namespace rdar13605348 { class C { - double operator"" _x(long double value) { return double(value); } // expected-error{{literal operator 'operator "" _x' must be in a namespace or global scope}} + double operator"" _x(long double value) { return double(value); } // expected-error{{literal operator 'operator""_x' must be in a namespace or global scope}} double value() { return 3.2_x; } // expected-error{{no matching literal operator for call to}} }; diff --git a/test/Lexer/hexfloat.cpp b/test/Lexer/hexfloat.cpp index bd53d4a89e..6985c7fbe2 100644 --- a/test/Lexer/hexfloat.cpp +++ b/test/Lexer/hexfloat.cpp @@ -12,4 +12,4 @@ double h = 0x1.p2; // expected-warning{{hexadecimal floating constants are a C99 double i = 0p+3; // expected-error{{invalid suffix 'p' on integer constant}} #define PREFIX(x) foo ## x double foo0p = 1, j = PREFIX(0p+3); // ok -double k = 0x42_amp+3; // expected-error-re{{{{invalid suffix '_amp' on integer constant|no matching literal operator for call to 'operator "" _amp'}}}} +double k = 0x42_amp+3; // expected-error-re{{{{invalid suffix '_amp' on integer constant|no matching literal operator for call to 'operator""_amp'}}}} diff --git a/test/Parser/cxx11-user-defined-literals.cpp b/test/Parser/cxx11-user-defined-literals.cpp index b89a574186..d3188f8f43 100644 --- a/test/Parser/cxx11-user-defined-literals.cpp +++ b/test/Parser/cxx11-user-defined-literals.cpp @@ -77,21 +77,21 @@ const char *p = erk flux )x" "eep\x1f"\ -_no_such_suffix // expected-error {{'operator "" _no_such_suffix'}} +_no_such_suffix // expected-error {{'operator""_no_such_suffix'}} "and a bit more" "and another suffix"_no_such_suffix; char c = '\x14'\ -_no_such_suffix; // expected-error {{'operator "" _no_such_suffix'}} +_no_such_suffix; // expected-error {{'operator""_no_such_suffix'}} int &r = 1234567\ -_no_such_suffix; // expected-error {{'operator "" _no_such_suffix'}} +_no_such_suffix; // expected-error {{'operator""_no_such_suffix'}} int k = 1234567.89\ -_no_such_suffix; // expected-error {{'operator "" _no_such_suffix'}} +_no_such_suffix; // expected-error {{'operator""_no_such_suffix'}} // Make sure we handle more interesting ways of writing a string literal which // is "" in translation phase 7. @@ -115,15 +115,15 @@ void operator "" u8"" "\u0123" "hello"_all_of_the_things ""(const char*); // exp // Make sure we treat UCNs and UTF-8 as equivalent. int operator""_µs(unsigned long long) {} // expected-note {{previous}} int hundred_µs = 50_µs + 50_\u00b5s; -int operator""_\u00b5s(unsigned long long) {} // expected-error {{redefinition of 'operator "" _µs'}} +int operator""_\u00b5s(unsigned long long) {} // expected-error {{redefinition of 'operator""_µs'}} int operator""_\U0000212B(long double) {} // expected-note {{previous}} int hundred_Å = 50.0_Å + 50._\U0000212B; -int operator""_Å(long double) {} // expected-error {{redefinition of 'operator "" _Å'}} +int operator""_Å(long double) {} // expected-error {{redefinition of 'operator""_Å'}} int operator""_𐀀(char) {} // expected-note {{previous}} int 𐀀 = '4'_𐀀 + '2'_\U00010000; -int operator""_\U00010000(char) {} // expected-error {{redefinition of 'operator "" _𐀀'}} +int operator""_\U00010000(char) {} // expected-error {{redefinition of 'operator""_𐀀'}} // These all declare the same function. int operator""_℮""_\u212e""_\U0000212e""(const char*, size_t); diff --git a/test/SemaCXX/cxx11-ast-print.cpp b/test/SemaCXX/cxx11-ast-print.cpp index 27726dedb4..1eeb67a3d9 100644 --- a/test/SemaCXX/cxx11-ast-print.cpp +++ b/test/SemaCXX/cxx11-ast-print.cpp @@ -1,21 +1,21 @@ // RUN: %clang_cc1 -std=c++11 -ast-print %s | FileCheck %s -// CHECK: auto operator "" _foo(const char *p, decltype(sizeof(int))) -> decltype(nullptr); +// CHECK: auto operator""_foo(const char *p, decltype(sizeof(int))) -> decltype(nullptr); auto operator"" _foo(const char *p, decltype(sizeof(int))) -> decltype(nullptr); -// CHECK: decltype(""_foo) operator "" _bar(unsigned long long); +// CHECK: decltype(""_foo) operator""_bar(unsigned long long); decltype(""_foo) operator"" _bar(unsigned long long); -// CHECK: decltype(42_bar) operator "" _baz(long double); +// CHECK: decltype(42_bar) operator""_baz(long double); decltype(42_bar) operator"" _baz(long double); -// CHECK: decltype(4.5_baz) operator "" _baz(char); +// CHECK: decltype(4.5_baz) operator""_baz(char); decltype(4.5_baz) operator"" _baz(char); -// CHECK: const char *operator "" _quux(const char *); +// CHECK: const char *operator""_quux(const char *); const char *operator"" _quux(const char *); -// CHECK: template const char *operator "" _fritz(); +// CHECK: template const char *operator""_fritz(); template const char *operator"" _fritz(); // CHECK: const char *p1 = "bar1"_foo; @@ -40,7 +40,7 @@ const char *p9 = 0x42e3F_fritz; const char *p10 = 3.300e+15_fritz; template const char *operator"" _suffix(); -// CHECK: const char *PR23120 = operator "" _suffix(); +// CHECK: const char *PR23120 = operator""_suffix(); const char *PR23120 = U"𐐷"_suffix; // CHECK: ; diff --git a/test/SemaCXX/cxx11-user-defined-literals.cpp b/test/SemaCXX/cxx11-user-defined-literals.cpp index cb7796418e..b5d4d9976c 100644 --- a/test/SemaCXX/cxx11-user-defined-literals.cpp +++ b/test/SemaCXX/cxx11-user-defined-literals.cpp @@ -70,7 +70,7 @@ namespace Using { namespace M { int operator"" _using(char); } - int k1 = 'x'_using; // expected-error {{no matching literal operator for call to 'operator "" _using'}} + int k1 = 'x'_using; // expected-error {{no matching literal operator for call to 'operator""_using'}} using M::operator "" _using; int k2 = 'x'_using; @@ -80,7 +80,7 @@ namespace AmbiguousRawTemplate { int operator"" _ambig1(const char *); // expected-note {{candidate}} template int operator"" _ambig1(); // expected-note {{candidate}} - int k1 = 123_ambig1; // expected-error {{call to 'operator "" _ambig1' is ambiguous}} + int k1 = 123_ambig1; // expected-error {{call to 'operator""_ambig1' is ambiguous}} namespace Inner { template int operator"" _ambig2(); // expected-note 3{{candidate}} @@ -88,7 +88,7 @@ namespace AmbiguousRawTemplate { int operator"" _ambig2(const char *); // expected-note 3{{candidate}} using Inner::operator"" _ambig2; - int k2 = 123_ambig2; // expected-error {{call to 'operator "" _ambig2' is ambiguous}} + int k2 = 123_ambig2; // expected-error {{call to 'operator""_ambig2' is ambiguous}} namespace N { using Inner::operator"" _ambig2; @@ -133,13 +133,13 @@ namespace Namespace { int k = _x(); // expected-error {{undeclared identifier '_x'}} int _y(unsigned long long); - int k2 = 123_y; // expected-error {{no matching literal operator for call to 'operator "" _y'}} + int k2 = 123_y; // expected-error {{no matching literal operator for call to 'operator""_y'}} } namespace PR14950 { template<...> // expected-error {{expected template parameter}} int operator"" _b(); // expected-error {{no function template matches function template specialization}} - int main() { return 0_b; } // expected-error {{no matching literal operator for call to 'operator "" _b'}} + int main() { return 0_b; } // expected-error {{no matching literal operator for call to 'operator""_b'}} } namespace bad_names { diff --git a/test/SemaCXX/literal-operators.cpp b/test/SemaCXX/literal-operators.cpp index f4c5c35a2b..ba571788b9 100644 --- a/test/SemaCXX/literal-operators.cpp +++ b/test/SemaCXX/literal-operators.cpp @@ -1,9 +1,9 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s #include struct tag { - void operator "" _tag_bad (const char *); // expected-error {{literal operator 'operator "" _tag_bad' must be in a namespace or global scope}} + void operator "" _tag_bad (const char *); // expected-error {{literal operator 'operator""_tag_bad' must be in a namespace or global scope}} friend void operator "" _tag_good (const char *); }; @@ -35,10 +35,14 @@ typedef const char c; void operator "" _good (c*); // Check extra cv-qualifiers -void operator "" _cv_good (volatile const char *, const size_t); // expected-error {{parameter declaration for literal operator 'operator "" _cv_good' is not valid}} +void operator "" _cv_good (volatile const char *, const size_t); // expected-error {{parameter declaration for literal operator 'operator""_cv_good' is not valid}} // Template declaration template void operator "" _good (); // FIXME: Test some invalid decls that might crop up. -template void operator "" _invalid(); // expected-error {{parameter declaration for literal operator 'operator "" _invalid' is not valid}} +template void operator "" _invalid(); // expected-error {{parameter declaration for literal operator 'operator""_invalid' is not valid}} + +_Complex float operator""if(long double); // expected-warning {{reserved}} +_Complex float test_if_1() { return 2.0f + 1.5if; }; +void test_if_2() { "foo"if; } // expected-error {{no matching literal operator for call to 'operator""if'}} -- 2.40.0