Bug 110342 - [C++26] P2361R6 - Unevaluated strings
Summary: [C++26] P2361R6 - Unevaluated strings
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 14.0
: P3 normal
Target Milestone: ---
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks: c++26-core
  Show dependency treegraph
 
Reported: 2023-06-21 16:10 UTC by Marek Polacek
Modified: 2023-11-02 06:48 UTC (History)
2 users (show)

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


Attachments
gcc14-pr110342.patch (4.81 KB, patch)
2023-08-23 11:47 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Marek Polacek 2023-06-21 16:10:55 UTC
See <https://wg21.link/P2361R6>.
Comment 1 Andrew Pinski 2023-06-22 06:18:09 UTC
Confirmed.
Comment 2 Jakub Jelinek 2023-08-23 11:47:05 UTC
Created attachment 55779 [details]
gcc14-pr110342.patch

Untested implementation.
Comment 3 Jiang An 2023-08-24 07:44:26 UTC
It seems that the paper also makes the GNU assembly syntax conforming. Should we make some other changes?
Comment 4 GCC Commits 2023-11-02 06:46:29 UTC
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:1c58566450f21cf1d9951284176ea6da0cc11fc9

commit r14-5071-g1c58566450f21cf1d9951284176ea6da0cc11fc9
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Nov 2 07:44:24 2023 +0100

    c++: Implement C++26 P2361R6 - Unevaluated strings [PR110342]
    
    The following patch implements C++26 unevaluated-string.
    As it seems to me just extra pedanticity, it is implemented only for
    -std=c++26 or -std=gnu++26 and later and only if -pedantic/-pedantic-errors.
    Nothing is done for inline asm, while the spec changes those, it changes it
    to a balanced token sequence with implementation defined rules on what is
    and isn't allowed (so pedantically accepting asm ("" : "+m" (x));
    was accepts-invalid before C++26, but we didn't diagnose anything).
    For the other spots mentioned in the paper, static_assert message,
    linkage specification, deprecated/nodiscard attributes it enforces the
    requirements (no prefixes, udlit suffixes, no octal/hexadecimal escapes
    (conditional escape sequences were rejected with pedantic already before).
    For the deprecated operator "" identifier case I've kept things as is,
    because everything seems to have been diagnosed already (a lot being implied
    from the string having to be empty).
    
    2023-11-02  Jakub Jelinek  <jakub@redhat.com>
    
            PR c++/110342
    gcc/cp/
            * parser.cc: Implement C++26 P2361R6 - Unevaluated strings.
            (uneval_string_attr): New enumerator.
            (cp_parser_string_literal_common): Add UNEVAL argument.  If true,
            pass CPP_UNEVAL_STRING rather than CPP_STRING to
            cpp_interpret_string_notranslate.
            (cp_parser_string_literal, cp_parser_userdef_string_literal): Adjust
            callers of cp_parser_string_literal_common.
            (cp_parser_unevaluated_string_literal): New function.
            (cp_parser_parenthesized_expression_list): Handle uneval_string_attr.
            (cp_parser_linkage_specification): Use
            cp_parser_unevaluated_string_literal for C++26.
            (cp_parser_static_assert): Likewise.
            (cp_parser_std_attribute): Use uneval_string_attr for standard
            deprecated and nodiscard attributes.
    gcc/testsuite/
            * g++.dg/cpp26/unevalstr1.C: New test.
            * g++.dg/cpp26/unevalstr2.C: New test.
            * g++.dg/cpp0x/udlit-error1.C (lol): Expect an error for C++26
            about user-defined literal in deprecated attribute.
    libcpp/
            * include/cpplib.h (TTYPE_TABLE): Add CPP_UNEVAL_STRING literal
            entry.  Use C++11 instead of C++-0x in comments.
            * charset.cc (convert_escape): Add UNEVAL argument, if true,
            pedantically diagnose numeric escape sequences.
            (cpp_interpret_string_1): Formatting fix.  Adjust convert_escape
            caller.
            (cpp_interpret_string): Formatting string.
            (cpp_interpret_string_notranslate): Pass type through to
            cpp_interpret_string if it is CPP_UNEVAL_STRING.
Comment 5 Jakub Jelinek 2023-11-02 06:48:43 UTC
Implemented now.