serge-sans-paille updated this revision to Diff 352938.
serge-sans-paille added a comment.
Reviews taken into account, I'm just not 100% sure of the fixit part. The out
is the following:
a.cpp:4:16: warning: identifier '_Bye' is reserved because it starts with '_'
followed by a capital letter [-Wreserved-identifier]
int operator"" _Bye(const char* s) {
~~~~~~~~~~~^~~~
operator""_Bye
1 warning generated.
Does that look good to you?
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D104299/new/
https://reviews.llvm.org/D104299
Files:
clang/include/clang/Sema/Sema.h
clang/lib/AST/Decl.cpp
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/Sema/reserved-identifier.cpp
Index: clang/test/Sema/reserved-identifier.cpp
===================================================================
--- clang/test/Sema/reserved-identifier.cpp
+++ clang/test/Sema/reserved-identifier.cpp
@@ -76,7 +76,12 @@
int _barbatruc; // no-warning
}
-long double operator"" _BarbeBleue(long double) // expected-warning {{identifier 'operator""_BarbeBleue' is reserved because it starts with '_' followed by a capital letter}}
+long double operator"" _BarbeBleue(long double) // expected-warning {{identifier '_BarbeBleue' is reserved because it starts with '_' followed by a capital letter}}
+{
+ return 0.;
+}
+
+long double operator""_SacreBleue(long double) // no-warning
{
return 0.;
}
Index: clang/lib/Sema/SemaExprCXX.cpp
===================================================================
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -484,8 +484,25 @@
}
bool Sema::checkLiteralOperatorId(const CXXScopeSpec &SS,
- const UnqualifiedId &Name) {
+ const UnqualifiedId &Name, bool isUDSuffix) {
assert(Name.getKind() == UnqualifiedIdKind::IK_LiteralOperatorId);
+ if (!isUDSuffix) {
+ // [over.literal] p8
+ // double operator""_Bq(long double); // OK: does not use
+ // the reserved identifier _ÂBq ([lex.name]) double operator"" _Bq(long
+ // double); // ill-formed, no diagnostic required:
+ IdentifierInfo *II = Name.Identifier;
+ auto Status = II->isReserved(PP.getLangOpts());
+ auto Loc = Name.getEndLoc();
+ if (Status != ReservedIdentifierStatus::NotReserved &&
+ !PP.getSourceManager().isInSystemHeader(Loc)) {
+ Diag(Loc, diag::warn_reserved_extern_symbol)
+ << II << static_cast<int>(Status)
+ << FixItHint::CreateReplacement(
+ Name.getSourceRange(),
+ (StringRef("operator\"\"") + II->getName()).str());
+ }
+ }
if (!SS.isValid())
return false;
Index: clang/lib/Parse/ParseExprCXX.cpp
===================================================================
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -9,7 +9,6 @@
// This file implements the Expression parsing implementation for C++.
//
//===----------------------------------------------------------------------===//
-#include "clang/Parse/Parser.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclTemplate.h"
@@ -17,6 +16,7 @@
#include "clang/Basic/PrettyStackTrace.h"
#include "clang/Lex/LiteralSupport.h"
#include "clang/Parse/ParseDiagnostic.h"
+#include "clang/Parse/Parser.h"
#include "clang/Parse/RAIIObjectsForParser.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/ParsedTemplate.h"
@@ -2636,9 +2636,10 @@
// Grab the literal operator's suffix, which will be either the next token
// or a ud-suffix from the string literal.
+ const bool isUDSuffix = !Literal.getUDSuffix().empty();
IdentifierInfo *II = nullptr;
SourceLocation SuffixLoc;
- if (!Literal.getUDSuffix().empty()) {
+ if (isUDSuffix) {
II = &PP.getIdentifierTable().get(Literal.getUDSuffix());
SuffixLoc =
Lexer::AdvanceToTokenCharacter(TokLocs[Literal.getUDSuffixToken()],
@@ -2675,7 +2676,7 @@
Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc);
- return Actions.checkLiteralOperatorId(SS, Result);
+ return Actions.checkLiteralOperatorId(SS, Result, isUDSuffix);
}
// Parse a conversion-function-id.
Index: clang/lib/AST/Decl.cpp
===================================================================
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1081,10 +1081,9 @@
ReservedIdentifierStatus
NamedDecl::isReserved(const LangOptions &LangOpts) const {
const IdentifierInfo *II = getIdentifier();
- if (!II)
- if (const auto *FD = dyn_cast<FunctionDecl>(this))
- II = FD->getLiteralIdentifier();
+ // This triggers at least for CXXLiteralIdentifiers, which we already checked
+ // at lexing time.
if (!II)
return ReservedIdentifierStatus::NotReserved;
Index: clang/include/clang/Sema/Sema.h
===================================================================
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -4128,7 +4128,8 @@
bool RValueThis, unsigned ThisQuals);
CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class);
- bool checkLiteralOperatorId(const CXXScopeSpec &SS, const UnqualifiedId &Id);
+ bool checkLiteralOperatorId(const CXXScopeSpec &SS, const UnqualifiedId &Id,
+ bool IsUDSuffix);
LiteralOperatorLookupResult
LookupLiteralOperator(Scope *S, LookupResult &R, ArrayRef<QualType> ArgTys,
bool AllowRaw, bool AllowTemplate,
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits