This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Produce a warning instead of an error in unevaluated strings before C++26
ClosedPublic

Authored by cor3ntin on Jul 29 2023, 7:04 AM.

Diff Detail

Event Timeline

cor3ntin created this revision.Jul 29 2023, 7:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 29 2023, 7:04 AM
cor3ntin requested review of this revision.Jul 29 2023, 7:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 29 2023, 7:04 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
cor3ntin updated this revision to Diff 545374.Jul 29 2023, 7:23 AM

Format + Add FixIt tests

Please add more details to the patch summary explaining why you're making these changes. Also, I assume this is to be backported to Clang 17? If so, I'd like @hubert.reinterpretcast to mention if this works for his needs.

Oups, sorry, the context is this PR https://reviews.llvm.org/D105759#4543246

I kind of figured. :-) But we want the context in the patch summary since that's what typically makes it to the commit message, and we don't want folks doing code archeology to have to click through to figure that context out.

clang/test/SemaCXX/static-assert.cpp
44–45

I doubt that it is a problem, but Clang 16 accepted such hex escapes.

cor3ntin added inline comments.Aug 1 2023, 1:00 AM
clang/test/CXX/dcl.dcl/dcl.link/p2.cpp
11–14

Note that was ill-formed in clang 16, despite being well-formed in the standard.

clang/test/SemaCXX/static-assert.cpp
44–45

Yes, I only downgraded to a warning what you had reports about.
I haven't seen that pattern in the wild and i don't think anyone who would use that isn't confused on some level.

If so, I'd like @hubert.reinterpretcast to mention if this works for his needs.

We are putting together a build for the (known) affected groups. I will report back when we have results.

clang/include/clang/Basic/DiagnosticLexKinds.td
290

I am not seeing any tests covering C mode.

@aaron.ballman, can you confirm that you are okay with the warning when processing C code (and, moreover, the newly-added errors for numeric escape sequences)?

aaron.ballman added inline comments.Aug 1 2023, 12:41 PM
clang/include/clang/Basic/DiagnosticLexKinds.td
290

Good call on C test coverage, thank you for bringing that up!

I think the behavior in C is reasonable, even if it's not mandated by the standard. We're going from issuing an error in C to issuing a warning and the warning text helpfully omits the C++2c part of the diagnostic, so it seems like we're more relaxed in C than we previously were.

Do you have concerns about the behavior in C? (Or are you saying you'd prefer this to be an error in C as it was before?)

clang/include/clang/Basic/DiagnosticLexKinds.td
290

My question was with respect to the change from the Clang 16 status quo for numeric escapes introduced by the prior change and carried forward with this one: https://godbolt.org/z/aneGr1Yfb

_Static_assert(1, "\x30"); // error in Clang 17
cor3ntin added inline comments.Aug 1 2023, 1:52 PM
clang/include/clang/Basic/DiagnosticLexKinds.td
290

Yes, this is intended, numeric escape sequences in unevaluated string literals are not allowed in any language modes - the motivation for C is the same as C++.

aaron.ballman added inline comments.Aug 2 2023, 5:29 AM
clang/include/clang/Basic/DiagnosticLexKinds.td
290

Barring evidence that we're breaking working code without workarounds, I'm happy with the behavior in C. I don't think numeric escape sequences make a lot of sense in the contexts where these strings appear in C, same as for C++. However, if we had evidence that this breaks working code in problematic ways, we could consider changing it to warning-defaults-to-error.

Note: we are waiting for feedback from @hubert.reinterpretcast's people before progressing this.

Note: we are waiting for feedback from @hubert.reinterpretcast's people before progressing this.

The "full" build hit some (unrelated) snags, but the initial results look good. The patch is awaiting C test cases.

cor3ntin updated this revision to Diff 548503.Aug 9 2023, 12:55 AM

Add C tests

aaron.ballman accepted this revision.Aug 9 2023, 8:26 AM

LGTM but please wait for @hubert.reinterpretcast to confirm the new tests cover what he was looking for.

This revision is now accepted and ready to land.Aug 9 2023, 8:26 AM

LGTM but please wait for @hubert.reinterpretcast to confirm the new tests cover what he was looking for.

LGTM; thanks!