-
Notifications
You must be signed in to change notification settings - Fork 15k
[clang][Parse] Use consistent Scope::ScopeFlags enum values (NFC) #159275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang][Parse] Use consistent Scope::ScopeFlags enum values (NFC) #159275
Conversation
Commit 438863a changed the underlying type of the Scope::ScopeFlags from int to unsigned. This triggers type mismatch warnings from specific compilers when the enum's values are combined in operations with integer literal 0. Regardless of these warnings, similar code in other places uses Scope::NoScope instead of literal 0. For consistency and to avoid these warnings, we change the uses of literal 0 to Scope::NoScope.
|
@llvm/pr-subscribers-clang Author: Bruno De Fraine (brunodf-snps) ChangesCommit 438863a changed the underlying type of the Scope::ScopeFlags from int to unsigned. This triggers type mismatch warnings from specific compilers when the enum's values are combined in operations with integer literal 0. Regardless of these warnings, similar code in other places uses Scope::NoScope instead of literal 0. For consistency and to avoid these warnings, we change the uses of literal 0 to Scope::NoScope. Full diff: https://github.com/llvm/llvm-project/pull/159275.diff 3 Files Affected:
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index bbeee2e3e373f..22c01c4e371f3 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -6813,10 +6813,10 @@ void Parser::ParseDirectDeclarator(Declarator &D) {
bool IsFunctionDeclaration = D.isFunctionDeclaratorAFunctionDeclaration();
// Enter function-declaration scope, limiting any declarators to the
// function prototype scope, including parameter declarators.
- ParseScope PrototypeScope(this,
- Scope::FunctionPrototypeScope|Scope::DeclScope|
- (IsFunctionDeclaration
- ? Scope::FunctionDeclarationScope : 0));
+ ParseScope PrototypeScope(
+ this, Scope::FunctionPrototypeScope | Scope::DeclScope |
+ (IsFunctionDeclaration ? Scope::FunctionDeclarationScope
+ : Scope::NoScope));
// The paren may be part of a C++ direct initializer, eg. "int x(1);".
// In such a case, check if we actually have a function declarator; if it
@@ -7097,8 +7097,9 @@ void Parser::ParseParenDeclarator(Declarator &D) {
// function prototype scope, including parameter declarators.
ParseScope PrototypeScope(this,
Scope::FunctionPrototypeScope | Scope::DeclScope |
- (D.isFunctionDeclaratorAFunctionDeclaration()
- ? Scope::FunctionDeclarationScope : 0));
+ (D.isFunctionDeclaratorAFunctionDeclaration()
+ ? Scope::FunctionDeclarationScope
+ : Scope::NoScope));
ParseFunctionDeclarator(D, attrs, T, false, RequiresArg);
PrototypeScope.Exit();
}
diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp
index 291c70e7bad4b..a64fb02294c5a 100644
--- a/clang/lib/Parse/ParseObjc.cpp
+++ b/clang/lib/Parse/ParseObjc.cpp
@@ -3295,9 +3295,9 @@ void Parser::ParseLexedObjCMethodDefs(LexedMethod &LM, bool parseMethod) {
assert(Tok.isOneOf(tok::l_brace, tok::kw_try, tok::colon) &&
"Inline objective-c method not starting with '{' or 'try' or ':'");
// Enter a scope for the method or c-function body.
- ParseScope BodyScope(this, (parseMethod ? Scope::ObjCMethodScope : 0) |
- Scope::FnScope | Scope::DeclScope |
- Scope::CompoundStmtScope);
+ ParseScope BodyScope(
+ this, (parseMethod ? Scope::ObjCMethodScope : Scope::NoScope) |
+ Scope::FnScope | Scope::DeclScope | Scope::CompoundStmtScope);
Sema::FPFeaturesStateRAII SaveFPFeatures(Actions);
// Tell the actions module that we have entered a method or c-function definition
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index 62361c066a3f3..2e7af1219547e 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -2529,9 +2529,9 @@ StmtResult Parser::ParseCXXTryBlockCommon(SourceLocation TryLoc, bool FnTry) {
return StmtError(Diag(Tok, diag::err_expected) << tok::l_brace);
StmtResult TryBlock(ParseCompoundStatement(
- /*isStmtExpr=*/false, Scope::DeclScope | Scope::TryScope |
- Scope::CompoundStmtScope |
- (FnTry ? Scope::FnTryCatchScope : 0)));
+ /*isStmtExpr=*/false,
+ Scope::DeclScope | Scope::TryScope | Scope::CompoundStmtScope |
+ (FnTry ? Scope::FnTryCatchScope : Scope::NoScope)));
if (TryBlock.isInvalid())
return TryBlock;
@@ -2593,9 +2593,9 @@ StmtResult Parser::ParseCXXCatchBlock(bool FnCatch) {
// C++ 3.3.2p3:
// The name in a catch exception-declaration is local to the handler and
// shall not be redeclared in the outermost block of the handler.
- ParseScope CatchScope(this, Scope::DeclScope | Scope::ControlScope |
- Scope::CatchScope |
- (FnCatch ? Scope::FnTryCatchScope : 0));
+ ParseScope CatchScope(
+ this, Scope::DeclScope | Scope::ControlScope | Scope::CatchScope |
+ (FnCatch ? Scope::FnTryCatchScope : Scope::NoScope));
// exception-declaration is equivalent to '...' or a parameter-declaration
// without default arguments.
|
|
This is an example of the warning triggered when using literal 0: https://godbolt.org/z/1zcb488rr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
|
Tagging @cor3ntin @erichkeane @Sirraide |
Commit 438863a changed the underlying type of the Scope::ScopeFlags from int to unsigned. This triggers type mismatch warnings from specific compilers when the enum's values are combined in operations with integer literal 0. Regardless of these warnings, similar code in other places uses Scope::NoScope instead of literal 0. For consistency and to avoid these warnings, we change the uses of literal 0 to Scope::NoScope.