Skip to content

[clang][Diagnostic] Don't warn about binary literals when using C23. #80244

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

Closed
wants to merge 1 commit into from

Conversation

collinfunk
Copy link

The C23 standard brought binary literals which were previously GNU extensions. Silence warnings from -Wgnu-binary-literal when using C23. This warning is implied by -Wpedantic.

The C23 standard brought binary literals which were previously GNU
extensions. Silence warnings from -Wgnu-binary-literal when using C23.
This warning is implied by -Wpedantic.

Signed-off-by: Collin Funk <[email protected]>
Copy link

github-actions bot commented Feb 1, 2024

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Feb 1, 2024
@llvmbot
Copy link
Member

llvmbot commented Feb 1, 2024

@llvm/pr-subscribers-clang

Author: Collin Funk (collinfunk)

Changes

The C23 standard brought binary literals which were previously GNU extensions. Silence warnings from -Wgnu-binary-literal when using C23. This warning is implied by -Wpedantic.


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

1 Files Affected:

  • (modified) clang/lib/Lex/LiteralSupport.cpp (+11-5)
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index 0a78638f68051..add4ca76678de 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -1358,11 +1358,17 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) {
 
   // Handle simple binary numbers 0b01010
   if ((c1 == 'b' || c1 == 'B') && (s[1] == '0' || s[1] == '1')) {
-    // 0b101010 is a C++1y / GCC extension.
-    Diags.Report(TokLoc, LangOpts.CPlusPlus14
-                             ? diag::warn_cxx11_compat_binary_literal
-                         : LangOpts.CPlusPlus ? diag::ext_binary_literal_cxx14
-                                              : diag::ext_binary_literal);
+    // 0b101010 is a GCC extension subsequently standardized by C23 and C++14.
+    if (LangOpts.CPlusPlus) {
+      if (LangOpts.CPlusPlus14)
+        Diags.Report(TokLoc, diag::warn_cxx11_compat_binary_literal);
+      else
+        Diags.Report(TokLoc, diag::ext_binary_literal_cxx14);
+    } else {
+      // TODO: Need new DiagGroup for C23.
+      if (!LangOpts.C23)
+        Diags.Report(TokLoc, diag::ext_binary_literal);
+    }
     ++s;
     assert(s < ThisTokEnd && "didn't maximally munch?");
     radix = 2;

@tbaederr tbaederr requested a review from AaronBallman February 1, 2024 06:11
Copy link
Collaborator

@shafik shafik left a comment

Choose a reason for hiding this comment

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

Thank you for this PR. This change should have some tests to verify the behavior is correct. I am a little surprised that this does not change any existing tests but maybe we don't have good test coverage.

@collinfunk
Copy link
Author

Thank you for this PR. This change should have some tests to verify the behavior is correct. I am a little surprised that this does not change any existing tests but maybe we don't have good test coverage.

Hi, thanks for the review. Sorry for the lack of tests. I'm not super familiar with LLVM's code and didn't know how to add them. In any case, I believe that this issue was fixed in the following pull requests along with better Diagnostic groups:

#81658

Can you double check and make sure I am not mistaken? Thanks.

@cor3ntin
Copy link
Contributor

cor3ntin commented Mar 7, 2024

#81658 replaces this PR

@cor3ntin cor3ntin closed this Mar 7, 2024
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