Skip to content

Commit c45eda6

Browse files
committed
Suppress diagnostic in the case where there is no leading underscore, which triggers other diagnostics
1 parent 21dc8df commit c45eda6

File tree

6 files changed

+16
-12
lines changed

6 files changed

+16
-12
lines changed

clang/lib/Basic/IdentifierTable.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,9 @@ ReservedLiteralSuffixIdStatus
406406
IdentifierInfo::isReservedLiteralSuffixId() const {
407407
StringRef Name = getName();
408408

409+
// Note: the diag::warn_deprecated_literal_operator_id diagnostic depends on
410+
// this being the first check we do, so if this order changes, we have to fix
411+
// that as well.
409412
if (Name[0] != '_')
410413
return ReservedLiteralSuffixIdStatus::NotStartsWithUnderscore;
411414

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,14 @@ bool Sema::checkLiteralOperatorId(const CXXScopeSpec &SS,
508508
Name.getSourceRange(),
509509
(StringRef("operator\"\"") + II->getName()).str());
510510

511-
Diag(Loc, diag::warn_deprecated_literal_operator_id) << II << Hint;
511+
// Only emit this diagnostic if we start with an underscore, else the
512+
// diagnostic for C++11 requiring a space between the quotes and the
513+
// identifier conflicts with this and gets confusing. The diagnostic stating
514+
// this is a reserved name should force the underscore, which gets this
515+
// back.
516+
if (II->isReservedLiteralSuffixId() !=
517+
ReservedLiteralSuffixIdStatus::NotStartsWithUnderscore)
518+
Diag(Loc, diag::warn_deprecated_literal_operator_id) << II << Hint;
512519

513520
if (isReservedInAllContexts(Status))
514521
Diag(Loc, diag::warn_reserved_extern_symbol)

clang/test/CXX/drs/cwg17xx.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,6 @@ namespace cwg1762 { // cwg1762: 14
203203
float operator ""E(const char *);
204204
// since-cxx11-error@-1 {{invalid suffix on literal; C++11 requires a space between literal and identifier}}
205205
// since-cxx11-warning@-2 {{user-defined literal suffixes not starting with '_' are reserved; no literal will invoke this operator}}
206-
// since-cxx11-warning@-3 {{identifier 'E' preceded by whitespace in a literal operator declaration is deprecated}}
207-
// FIXME: We could probably do a better job reacting to the fixit here, the
208-
// fact that we complain about the space we added is a little strange.
209206
#endif
210207
}
211208

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ namespace std {
88
void operator ""_km(long double); // ok
99
string operator ""_i18n(const char*, std::size_t); // ok
1010
template<char...> int operator ""\u03C0(); // ok, UCN for lowercase pi // expected-warning {{reserved}}
11-
float operator ""E(const char *); // expected-error {{invalid suffix on literal}} expected-warning {{reserved}} expected-warning{{whitespace}}
12-
float operator " " B(const char *); // expected-error {{must be '""'}} expected-warning {{reserved}} expected-warning{{whitespace}}
11+
float operator ""E(const char *); // expected-error {{invalid suffix on literal}} expected-warning {{reserved}}
12+
float operator " " B(const char *); // expected-error {{must be '""'}} expected-warning {{reserved}}
1313
string operator ""5X(const char *, std::size_t); // expected-error {{expected identifier}}
1414
double operator ""_miles(double); // expected-error {{parameter}}
15-
template<char...> int operator "" j(const char*); // expected-error {{template}} expected-warning{{whitespace}}
15+
template<char...> int operator "" j(const char*); // expected-error {{template}}
1616

1717
float operator ""_E(const char *);

clang/test/Parser/cxx0x-literal-operators.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
void operator "" (const char *); // expected-error {{expected identifier}}
44
void operator "k" foo(const char *); // \
55
expected-error {{string literal after 'operator' must be '""'}} \
6-
expected-warning{{user-defined literal suffixes not starting with '_' are reserved}} \
7-
expected-warning{{identifier 'foo' preceded by whitespace in a literal operator declaration is deprecated}}
6+
expected-warning{{user-defined literal suffixes not starting with '_' are reserved}}
87
void operator "" tester (const char *); // \
9-
expected-warning{{user-defined literal suffixes not starting with '_' are reserved}} \
10-
expected-warning{{identifier 'tester' preceded by whitespace in a literal operator declaration is deprecated}}
8+
expected-warning{{user-defined literal suffixes not starting with '_' are reserved}}

clang/test/SemaCXX/no-warn-user-defined-literals-in-system-headers.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
#include <no-warn-user-defined-literals-in-system-headers.h>
44

55
void operator "" bar(long double); // expected-warning{{user-defined literal suffixes not starting with '_' are reserved}}
6-
// expected-warning@-1{{identifier 'bar' preceded by whitespace in a literal operator declaration is deprecated}}

0 commit comments

Comments
 (0)