Bug 110340 - [C++26] P2621R2 - Remove undefined behavior from lexing
Summary: [C++26] P2621R2 - Remove undefined behavior from lexing
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 14.0
: P3 normal
Target Milestone: ---
Assignee: Marek Polacek
URL:
Keywords:
Depends on:
Blocks: c++26-core
  Show dependency treegraph
 
Reported: 2023-06-21 16:03 UTC by Marek Polacek
Modified: 2024-09-05 23:12 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-06-23 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marek Polacek 2023-06-21 16:03:56 UTC
See <https://wg21.link/P2621R2>.
Comment 1 Andrew Pinski 2023-06-21 21:20:20 UTC
Full testcase for the first 2 issues raised in the paper:
```
int \\
u\
0\
3\
9\
1 = 0;

#define CONCAT(x,y) x##y

int CONCAT(\,u0393)=0;
```

Testcase for the last one:
```
const char * foo=" // { dg-error "" }
```

as far as I understand from the paper, instead of the above being undefined at compiletime, the first testcase becomes valid and the last one becomes invalid. And right now GCC acts according to the paper already so there is not anything to be done. Maybe add a testcase for these if there is not already one is enough ...
Comment 2 Jason Merrill 2023-06-23 20:01:50 UTC
(In reply to Andrew Pinski from comment #1)
> Full testcase for the first 2 issues raised in the paper:

Thanks, want to add these to the testsuite and close the PR?
Comment 3 GCC Commits 2023-07-18 17:33:53 UTC
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:fca089e8a47314a40ad93527ba9f9d0d374b3afb

commit r14-2626-gfca089e8a47314a40ad93527ba9f9d0d374b3afb
Author: Marek Polacek <polacek@redhat.com>
Date:   Tue Jul 18 13:26:39 2023 -0400

    c++: Add tests for P2621, no UB in lexer [PR110340]
    
    C++26 P2621 removes UB in the lexer and either makes the construct valid
    or ill-formed.  We're already handling this correctly so this patch only
    adds tests.
    
            PR c++/110340
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp/string-4.C: New test.
            * g++.dg/cpp/ucn-2.C: New test.
Comment 4 Marek Polacek 2023-07-18 17:34:20 UTC
Done.