Skip to content

Commit d43daac

Browse files
author
git apple-llvm automerger
committed
Merge commit 'f2583f3acf59' from llvm.org/main into next
2 parents d682d3b + f2583f3 commit d43daac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+235
-274
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ C++2c Feature Support
9292

9393
Resolutions to C++ Defect Reports
9494
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
95+
- Implemented `CWG1473 <https://wg21.link/CWG1473>`_ which allows spaces after ``operator""``.
96+
Clang used to err on the lack of space when the literal suffix identifier was invalid in
97+
all the language modes, which contradicted the deprecation of the whitespaces.
98+
Also turn on ``-Wdeprecated-literal-operator`` by default in all the language modes.
9599

96100
C Language Changes
97101
------------------

clang/include/clang/Basic/DiagnosticLexKinds.td

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,6 @@ def warn_cxx11_compat_reserved_user_defined_literal : Warning<
276276
"identifier after literal will be treated as a reserved user-defined literal "
277277
"suffix in C++11">,
278278
InGroup<CXX11CompatReservedUserDefinedLiteral>, DefaultIgnore;
279-
def ext_reserved_user_defined_literal : ExtWarn<
280-
"invalid suffix on literal; C++11 requires a space between literal and "
281-
"identifier">, InGroup<ReservedUserDefinedLiteral>, DefaultError;
282-
def ext_ms_reserved_user_defined_literal : ExtWarn<
283-
"invalid suffix on literal; C++11 requires a space between literal and "
284-
"identifier">, InGroup<ReservedUserDefinedLiteral>;
285279
def err_unsupported_string_concat : Error<
286280
"unsupported non-standard concatenation of string literals">;
287281

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def warn_reserved_extern_symbol: Warning<
411411
InGroup<ReservedIdentifier>, DefaultIgnore;
412412
def warn_deprecated_literal_operator_id: Warning<
413413
"identifier %0 preceded by whitespace in a literal operator declaration "
414-
"is deprecated">, InGroup<DeprecatedLiteralOperator>, DefaultIgnore;
414+
"is deprecated">, InGroup<DeprecatedLiteralOperator>;
415415
def warn_reserved_module_name : Warning<
416416
"%0 is a reserved name for a module">, InGroup<ReservedModuleIdentifier>;
417417

clang/lib/Lex/Lexer.cpp

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,53 +2038,11 @@ const char *Lexer::LexUDSuffix(Token &Result, const char *CurPtr,
20382038
}
20392039

20402040
// C++11 [lex.ext]p10, [usrlit.suffix]p1: A program containing a ud-suffix
2041-
// that does not start with an underscore is ill-formed. As a conforming
2042-
// extension, we treat all such suffixes as if they had whitespace before
2043-
// them. We assume a suffix beginning with a UCN or UTF-8 character is more
2044-
// likely to be a ud-suffix than a macro, however, and accept that.
2045-
if (!Consumed) {
2046-
bool IsUDSuffix = false;
2047-
if (C == '_')
2048-
IsUDSuffix = true;
2049-
else if (IsStringLiteral && LangOpts.CPlusPlus14) {
2050-
// In C++1y, we need to look ahead a few characters to see if this is a
2051-
// valid suffix for a string literal or a numeric literal (this could be
2052-
// the 'operator""if' defining a numeric literal operator).
2053-
const unsigned MaxStandardSuffixLength = 3;
2054-
char Buffer[MaxStandardSuffixLength] = { C };
2055-
unsigned Consumed = Size;
2056-
unsigned Chars = 1;
2057-
while (true) {
2058-
unsigned NextSize;
2059-
char Next = getCharAndSizeNoWarn(CurPtr + Consumed, NextSize, LangOpts);
2060-
if (!isAsciiIdentifierContinue(Next)) {
2061-
// End of suffix. Check whether this is on the allowed list.
2062-
const StringRef CompleteSuffix(Buffer, Chars);
2063-
IsUDSuffix =
2064-
StringLiteralParser::isValidUDSuffix(LangOpts, CompleteSuffix);
2065-
break;
2066-
}
2067-
2068-
if (Chars == MaxStandardSuffixLength)
2069-
// Too long: can't be a standard suffix.
2070-
break;
2071-
2072-
Buffer[Chars++] = Next;
2073-
Consumed += NextSize;
2074-
}
2075-
}
2076-
2077-
if (!IsUDSuffix) {
2078-
if (!isLexingRawMode())
2079-
Diag(CurPtr, LangOpts.MSVCCompat
2080-
? diag::ext_ms_reserved_user_defined_literal
2081-
: diag::ext_reserved_user_defined_literal)
2082-
<< FixItHint::CreateInsertion(getSourceLocation(CurPtr), " ");
2083-
return CurPtr;
2084-
}
2085-
2041+
// that does not start with an underscore is ill-formed. We assume a suffix
2042+
// beginning with a UCN or UTF-8 character is more likely to be a ud-suffix
2043+
// than a macro, however, and accept that.
2044+
if (!Consumed)
20862045
CurPtr = ConsumeChar(CurPtr, Size, Result);
2087-
}
20882046

20892047
Result.setFlag(Token::HasUDSuffix);
20902048
while (true) {

clang/test/CXX/drs/dr14xx.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,17 @@ namespace dr1467 { // dr1467: 3.7 c++11
484484
#endif
485485
} // dr1467
486486

487+
namespace dr1473 { // dr1473: 18
488+
// NB: sup 1762, test reused there
489+
#if __cplusplus >= 201103L
490+
float operator ""_E(const char *);
491+
float operator ""E(const char *); // don't err on the lack of spaces even when the literal suffix identifier is invalid
492+
// expected-warning@-1 {{user-defined literal suffixes not starting with '_' are reserved; no literal will invoke this operator}}
493+
#endif
494+
}
495+
487496
namespace dr1479 { // dr1479: yes
488-
int operator"" _a(const char*, std::size_t = 0); // expected-error {{literal operator cannot have a default argument}}
497+
int operator""_a(const char*, std::size_t = 0); // expected-error {{literal operator cannot have a default argument}}
489498
}
490499

491500
namespace dr1482 { // dr1482: yes

clang/test/CXX/drs/dr17xx.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ namespace dr1758 { // dr1758: 3.7
139139
}
140140

141141
namespace dr1762 { // dr1762: 14
142+
// NB: reusing 1473 test
142143
#if __cplusplus >= 201103L
143144
float operator ""_E(const char *);
144-
// expected-error@+2 {{invalid suffix on literal; C++11 requires a space between literal and identifier}}
145-
// expected-warning@+1 {{user-defined literal suffixes not starting with '_' are reserved; no literal will invoke this operator}}
146145
float operator ""E(const char *);
146+
// expected-warning@-1 {{user-defined literal suffixes not starting with '_' are reserved; no literal will invoke this operator}}
147147
#endif
148148
}
149149

clang/test/CXX/drs/dr25xx.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ int test_specialization() {
6464

6565
namespace dr2521 { // dr2521: 17
6666
#if __cplusplus >= 201103L
67-
#pragma clang diagnostic push
68-
#pragma clang diagnostic warning "-Wdeprecated-literal-operator"
6967
long double operator"" _\u03C0___(long double);
7068
// expected-warning@-1 {{identifier '_π___' preceded by whitespace in a literal operator declaration is deprecated}}
7169
// expected-warning@-2 {{user-defined literal suffixes containing '__' are reserved}}
@@ -77,7 +75,6 @@ operator"" _div();
7775
using ::dr2521::operator"" _\u03C0___;
7876
using ::dr2521::operator""_div;
7977
// expected-warning@-2 {{identifier '_π___' preceded by whitespace in a literal operator declaration is deprecated}}
80-
#pragma clang diagnostic pop
8178
#endif
8279
} // namespace dr2521
8380

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
22

3-
void operator "" p31(long double); // expected-warning{{user-defined literal suffixes not starting with '_' are reserved}}
4-
void operator "" _p31(long double);
5-
long double operator "" pi(long double); // expected-warning{{user-defined literal suffixes not starting with '_' are reserved}}
3+
void operator ""p31(long double); // expected-warning{{user-defined literal suffixes not starting with '_' are reserved}}
4+
void operator ""_p31(long double);
5+
long double operator ""pi(long double); // expected-warning{{user-defined literal suffixes not starting with '_' are reserved}}
66

77
float hexfloat = 0x1p31; // allow hexfloats
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// RUN: %clang_cc1 -std=c++11 -verify %s
22

33
using size_t = decltype(sizeof(int));
4-
void operator "" wibble(const char *); // expected-warning {{user-defined literal suffixes not starting with '_' are reserved; no literal will invoke this operator}}
5-
void operator "" wibble(const char *, size_t); // expected-warning {{user-defined literal suffixes not starting with '_' are reserved; no literal will invoke this operator}}
4+
void operator ""wibble(const char *); // expected-warning {{user-defined literal suffixes not starting with '_' are reserved; no literal will invoke this operator}}
5+
void operator ""wibble(const char *, size_t); // expected-warning {{user-defined literal suffixes not starting with '_' are reserved; no literal will invoke this operator}}
66

77
template<typename T>
88
void f() {
99
// A program containing a reserved ud-suffix is ill-formed.
1010
123wibble; // expected-error {{invalid suffix 'wibble'}}
1111
123.0wibble; // expected-error {{invalid suffix 'wibble'}}
12-
const char *p = ""wibble; // expected-error {{invalid suffix on literal; C++11 requires a space between literal and identifier}} expected-error {{expected ';'}}
13-
const char *q = R"x("hello")x"wibble; // expected-error {{invalid suffix on literal; C++11 requires a space between literal and identifier}} expected-error {{expected ';'}}
12+
const char *p = ""wibble; // expected-error {{cannot initialize a variable of type 'const char *' with an rvalue of type 'void'}}
13+
const char *q = R"x("hello")x"wibble; // expected-error {{cannot initialize a variable of type 'const char *' with an rvalue of type 'void'}}
1414
}

clang/test/CXX/lex/lex.literal/lex.ext/p11.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ template<typename T, typename U> struct same_type;
66
template<typename T> struct same_type<T, T> {};
77
template<typename T> using X = T;
88
template<typename CharT, X<CharT>...>
9-
int operator "" _x(); // expected-warning {{string literal operator templates are a GNU extension}}
9+
int operator ""_x(); // expected-warning {{string literal operator templates are a GNU extension}}
1010
template<char...>
11-
double operator "" _x();
11+
double operator ""_x();
1212

1313
auto a="string"_x;
1414
auto b=42_x;
1515
same_type<decltype(a), int> test_a;
1616
same_type<decltype(b), double> test_b;
1717

18-
char operator "" _x(const char *begin, size_t size);
18+
char operator ""_x(const char *begin, size_t size);
1919
auto c="string"_x;
2020
auto d=L"string"_x;
2121
same_type<decltype(c), char> test_c;
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
22

3-
int &operator "" _x1 (unsigned long long);
3+
int &operator ""_x1 (unsigned long long);
44
int &i1 = 0x123_x1;
55

6-
double &operator "" _x1 (const char *);
6+
double &operator ""_x1 (const char *);
77
int &i2 = 45_x1;
88

9-
template<char...> char &operator "" _x1 ();
9+
template<char...> char &operator ""_x1 ();
1010
int &i3 = 0377_x1;
1111

1212
int &i4 = 90000000000000000000000000000000000000000000000_x1; // expected-error {{integer literal is too large to be represented in any integer type}}
1313

14-
double &operator "" _x2 (const char *);
14+
double &operator ""_x2 (const char *);
1515
double &i5 = 123123123123123123123123123123123123123123123_x2;
1616

17-
template<char...Cs> constexpr int operator "" _x3() { return sizeof...(Cs); }
17+
template<char...Cs> constexpr int operator ""_x3() { return sizeof...(Cs); }
1818
static_assert(123456789012345678901234567890123456789012345678901234567890_x3 == 60, "");
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
22

3-
int &operator "" _x1 (long double);
3+
int &operator ""_x1 (long double);
44
int &i1 = 0.123_x1;
55

6-
double &operator "" _x1 (const char *);
6+
double &operator ""_x1 (const char *);
77
int &i2 = 45._x1;
88

9-
template<char...> char &operator "" _x1 ();
9+
template<char...> char &operator ""_x1 ();
1010
int &i3 = 0377e-1_x1;
1111

1212
int &i4 = 1e1000000_x1; // expected-warning {{too large for type 'long double'}}
1313

14-
double &operator "" _x2 (const char *);
14+
double &operator ""_x2 (const char *);
1515
double &i5 = 1e1000000_x2;
1616

17-
template<char...Cs> constexpr int operator "" _x3() { return sizeof...(Cs); }
17+
template<char...Cs> constexpr int operator ""_x3() { return sizeof...(Cs); }
1818
static_assert(1e1000000_x3 == 9, "");

clang/test/CXX/lex/lex.literal/lex.ext/p5.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33

44
using size_t = decltype(sizeof(int));
55

6-
int &operator "" _x1 (const char *);
7-
double &operator "" _x1 (const char *, size_t);
6+
int &operator ""_x1 (const char *);
7+
double &operator ""_x1 (const char *, size_t);
88
double &i1 = "foo"_x1;
99
#if __cplusplus >= 202002L
1010
using char8 = float;
11-
float &operator "" _x1 (const char8_t *, size_t);
11+
float &operator ""_x1 (const char8_t *, size_t);
1212
#else
1313
using char8 = double;
1414
#endif
1515
char8 &i2 = u8"foo"_x1;
1616
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'}}
1717

18-
char &operator "" _x1(const wchar_t *, size_t);
18+
char &operator ""_x1(const wchar_t *, size_t);
1919
char &i4 = L"foo"_x1; // ok
2020
double &i5 = R"(foo)"_x1; // ok
2121
char8 &i6 = u\

clang/test/CXX/lex/lex.literal/lex.ext/p6.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
using size_t = decltype(sizeof(int));
44

5-
int &operator "" _x1 (const char *);
5+
int &operator ""_x1 (const char *);
66
double &i1 = 'a'_x1; // expected-error {{no matching literal operator}}
7-
double &operator "" _x1 (wchar_t);
7+
double &operator ""_x1 (wchar_t);
88
double &i2 = L'a'_x1;
99
double &i3 = 'a'_x1; // expected-error {{no matching literal operator}}
10-
double &i4 = operator"" _x1('a'); // ok
10+
double &i4 = operator""_x1('a'); // ok
1111

12-
char &operator "" _x1(char16_t);
12+
char &operator ""_x1(char16_t);
1313
char &i5 = u'a'_x1; // ok
1414
double &i6 = L'a'_x1; // ok

clang/test/CXX/lex/lex.literal/lex.ext/p7.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ template<typename T> struct same_type<T, T> {};
1010

1111
namespace std_example {
1212

13-
long double operator "" _w(long double);
14-
std::string operator "" _w(const char16_t*, size_t);
15-
unsigned operator "" _w(const char*);
13+
long double operator ""_w(long double);
14+
std::string operator ""_w(const char16_t*, size_t);
15+
unsigned operator ""_w(const char*);
1616
int main() {
1717
auto v1 = 1.2_w; // calls operator""_w(1.2L)
1818
auto v2 = u"one"_w; // calls operator""_w(u"one", 3)

clang/test/CXX/lex/lex.literal/lex.ext/p8.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// RUN: %clang_cc1 -std=c++11 -verify %s
22

33
using size_t = decltype(sizeof(int));
4-
constexpr const char *operator "" _id(const char *p, size_t) { return p; }
4+
constexpr const char *operator ""_id(const char *p, size_t) { return p; }
55
constexpr const char *s = "foo"_id "bar" "baz"_id "quux";
66

77
constexpr bool streq(const char *p, const char *q) {
88
return *p == *q && (!*p || streq(p+1, q+1));
99
}
1010
static_assert(streq(s, "foobarbazquux"), "");
1111

12-
constexpr const char *operator "" _trim(const char *p, size_t n) {
13-
return *p == ' ' ? operator "" _trim(p + 1, n - 1) : p;
12+
constexpr const char *operator ""_trim(const char *p, size_t n) {
13+
return *p == ' ' ? operator ""_trim(p + 1, n - 1) : p;
1414
}
1515
constexpr const char *t = " " " "_trim " foo";
1616
static_assert(streq(t, "foo"), "");

clang/test/CXX/lex/lex.literal/lex.ext/p9.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
22

33
using size_t = decltype(sizeof(int));
4-
void operator "" _x(const wchar_t *, size_t);
4+
void operator ""_x(const wchar_t *, size_t);
55

66
namespace std_example {
77

clang/test/CXX/over/over.oper/over.literal/p2.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
// RUN: %clang_cc1 -std=c++11 %s -verify
22

3-
void operator "" _a(const char *);
3+
void operator ""_a(const char *);
44

55
namespace N {
6-
using ::operator "" _a;
6+
using ::operator ""_a;
77

8-
void operator "" _b(const char *);
8+
void operator ""_b(const char *);
99
}
1010

11-
using N::operator "" _b;
11+
using N::operator ""_b;
1212

1313
class C {
14-
void operator "" _c(const char *); // expected-error {{must be in a namespace or global scope}}
14+
void operator ""_c(const char *); // expected-error {{must be in a namespace or global scope}}
1515

16-
static void operator "" _c(unsigned long long); // expected-error {{must be in a namespace or global scope}}
16+
static void operator ""_c(unsigned long long); // expected-error {{must be in a namespace or global scope}}
1717

18-
friend void operator "" _d(const char *);
18+
friend void operator ""_d(const char *);
1919
};
2020

21-
int operator "" _e; // expected-error {{cannot be the name of a variable}}
21+
int operator ""_e; // expected-error {{cannot be the name of a variable}}
2222

2323
void f() {
24-
int operator "" _f; // expected-error {{cannot be the name of a variable}}
24+
int operator ""_f; // expected-error {{cannot be the name of a variable}}
2525
}
2626

2727
extern "C++" {
28-
void operator "" _g(const char *);
28+
void operator ""_g(const char *);
2929
}
3030

31-
template<char...> void operator "" _h() {}
31+
template<char...> void operator ""_h() {}
3232

33-
template<> void operator "" _h<'a', 'b', 'c'>() {}
33+
template<> void operator ""_h<'a', 'b', 'c'>() {}
3434

35-
template void operator "" _h<'a', 'b', 'c', 'd'>();
35+
template void operator ""_h<'a', 'b', 'c', 'd'>();
3636

3737
namespace rdar13605348 {
3838

3939
class C {
40-
double operator"" _x(long double value) { return double(value); } // expected-error{{literal operator 'operator""_x' must be in a namespace or global scope}}
40+
double operator""_x(long double value) { return double(value); } // expected-error{{literal operator 'operator""_x' must be in a namespace or global scope}}
4141
double value() { return 3.2_x; } // expected-error{{no matching literal operator for call to}}
4242
};
4343

0 commit comments

Comments
 (0)