public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "janpmoeller at gmx dot de" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/105440] New: c++20: std::string's destructor not a constant expression when it should Date: Sat, 30 Apr 2022 13:28:52 +0000 [thread overview] Message-ID: <bug-105440-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105440 Bug ID: 105440 Summary: c++20: std::string's destructor not a constant expression when it should Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: janpmoeller at gmx dot de Target Milestone: --- The following valid c++20 program fails to compile on both gcc and clang when compiled with libstdc++: /************************************************************/ #include <string> #include <array> constexpr auto foo(char c){ std::array a{std::string{"foo"} + c}; return true; } static_assert(foo('a')); /************************************************************/ The emitted error is: /************************************************************/ <source>:9:18: error: non-constant condition for static assertion 9 | static_assert(foo('a')); | ~~~^~~~~ In file included from /opt/compiler-explorer/gcc-trunk-20220430/include/c++/13.0.0/string:53, from <source>:1: <source>:9:18: in 'constexpr' expansion of 'foo(97)' <source>:7:1: in 'constexpr' expansion of '(& a)->std::array<std::__cxx11::basic_string<char>, 1>::~array()' /opt/compiler-explorer/gcc-trunk-20220430/include/c++/13.0.0/array:99:12: in 'constexpr' expansion of '<anonymous>->std::__cxx11::basic_string<char>::~basic_string()' /opt/compiler-explorer/gcc-trunk-20220430/include/c++/13.0.0/bits/basic_string.h:795:19: in 'constexpr' expansion of '((std::__cxx11::basic_string<char>*)this)->std::__cxx11::basic_string<char>::_M_dispose()' /opt/compiler-explorer/gcc-trunk-20220430/include/c++/13.0.0/bits/basic_string.h:275:26: error: '((& a) == <anonymous>)' is not a constant expression 275 | { return _M_data() == _M_local_data(); } | ~~~~~~~~~~^~~~~~~~~~~~~~~~~~ Compiler returned: 1 /************************************************************/ The same program compiles with libc++, and on msvc. Also see the following godbolt link for comparison: https://godbolt.org/z/zfn1Pr7P1
next reply other threads:[~2022-04-30 13:28 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-04-30 13:28 janpmoeller at gmx dot de [this message] 2022-05-04 16:16 ` [Bug libstdc++/105440] " redi at gcc dot gnu.org 2023-04-17 14:27 ` ppalka at gcc dot gnu.org 2023-05-08 12:24 ` rguenth at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-105440-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).