Skip to content

[NFC][Clang] Fix enumerated mismatch warning #112816

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

Merged
merged 7 commits into from
Oct 22, 2024
Merged

Conversation

jsji
Copy link
Member

@jsji jsji commented Oct 18, 2024

This is one of the many PRs to fix errors with LLVM_ENABLE_WERROR=on. Built by GCC 11.

Fix warning:
llvm-project/clang/lib/Parse/ParseDeclCXX.cpp:3153:14: error: enumerated mismatch in conditional expression: ‘clang::diag::<unnamed enum>’ vs ‘clang::diag::<unnamed enum>’ [-Werror=enum-compare]
 3152 |          DS.isFriendSpecified() || NextToken().is(tok::kw_friend)
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 3153 |              ? diag::err_friend_concept
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~
 3154 |              : diag::
      |              ~~~~~~~~
 3155 |                    err_concept_decls_may_only_appear_in_global_namespace_scope);

@jsji jsji requested review from Sirraide and damyanp October 18, 2024 03:04
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Oct 18, 2024
@jsji jsji self-assigned this Oct 18, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 18, 2024

@llvm/pr-subscribers-clang

Author: Jinsong Ji (jsji)

Changes

This is one of the many PRs to fix errors with LLVM_ENABLE_WERROR=on. Built by GCC 11.

Fix warning:
llvm-project/clang/lib/Parse/ParseDeclCXX.cpp:3153:14: error: enumerated mismatch in conditional expression: ‘clang::diag::<unnamed enum>’ vs ‘clang::diag::<unnamed enum>’ [-Werror=enum-compare]
3152 | DS.isFriendSpecified() || NextToken().is(tok::kw_friend)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3153 | ? diag::err_friend_concept
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
3154 | : diag::
| ~~~~~~~~
3155 | err_concept_decls_may_only_appear_in_global_namespace_scope);


Full diff: https://github.com/llvm/llvm-project/pull/112816.diff

2 Files Affected:

  • (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (-3)
  • (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+2)
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 78510e61a639fa..cb52629f9c61c7 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -983,9 +983,6 @@ def warn_cxx23_variadic_friends : Warning<
   "variadic 'friend' declarations are incompatible with C++ standards before C++2c">,
   DefaultIgnore, InGroup<CXXPre26Compat>;
 
-def err_friend_concept : Error<
-  "friend declaration cannot be a concept">;
-
 // C++11 default member initialization
 def ext_nonstatic_member_init : ExtWarn<
   "default member initializer for non-static data member is a C++11 "
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 883db838ca0147..d102a45f8c1ed2 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3020,6 +3020,8 @@ def err_c23_constexpr_pointer_not_null : Error<
   "constexpr pointer initializer is not null">;
 
 // C++ Concepts
+def err_friend_concept : Error<
+  "friend declaration cannot be a concept">;
 def err_concept_decls_may_only_appear_in_global_namespace_scope : Error<
   "concept declarations may only appear in global or namespace scope">;
 def err_concept_no_parameters : Error<

Copy link
Member

@Sirraide Sirraide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn’t seem right: that diagnostic is only used in the parser, which is why it is in DiagnosticParseKinds.td. Instead, it’d be better to cast the two diagnostic IDs that are causing the problem to unsigned where they’re used.

@jsji jsji requested a review from Sirraide October 18, 2024 13:11
@jsji jsji requested a review from Sirraide October 18, 2024 15:00
@damyanp damyanp removed their request for review October 18, 2024 16:53
@jsji jsji force-pushed the diagtypemistmatch branch from 3c71acf to 54c5791 Compare October 19, 2024 13:26
@jsji jsji requested a review from cor3ntin October 19, 2024 16:24
jsji and others added 6 commits October 21, 2024 12:37
This is one of the many PRs to fix errors with LLVM_ENABLE_WERROR=on. Built by GCC 11.

Fix warning:
llvm-project/clang/lib/Parse/ParseDeclCXX.cpp:3153:14: error: enumerated mismatch in conditional expression: ‘clang::diag::<unnamed enum>’ vs ‘clang::diag::<unnamed enum>’ [-Werror=enum-compare]
 3152 |          DS.isFriendSpecified() || NextToken().is(tok::kw_friend)
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 3153 |              ? diag::err_friend_concept
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~
 3154 |              : diag::
      |              ~~~~~~~~
 3155 |                    err_concept_decls_may_only_appear_in_global_namespace_scope);
@jsji jsji force-pushed the diagtypemistmatch branch from b593d0c to 3554070 Compare October 21, 2024 16:37
@jsji
Copy link
Member Author

jsji commented Oct 22, 2024

@Sirraide @cor3ntin Updated, can you please have another look? Thanks.

Copy link
Member

@Sirraide Sirraide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jsji jsji merged commit b81d8e9 into llvm:main Oct 22, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants