public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/106485] New: Can't use heap pointer in `static_assert` @ 2022-07-30 19:58 johelegp at gmail dot com 2022-07-30 22:16 ` [Bug c++/106485] " pinskia at gcc dot gnu.org ` (3 more replies) 0 siblings, 4 replies; 5+ messages in thread From: johelegp at gmail dot com @ 2022-07-30 19:58 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106485 Bug ID: 106485 Summary: Can't use heap pointer in `static_assert` Product: gcc Version: 13.0 Status: UNCONFIRMED Keywords: rejects-valid Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: johelegp at gmail dot com CC: johelegp at gmail dot com Target Milestone: --- See https://godbolt.org/z/W4r6oMa3M. ```C++ struct I { int* i = new int{1}; constexpr ~I() { delete i; } }; static_assert([] { return I{}.i; }()); static_assert(I{}.i); ``` ``` <source>:5:19: error: non-constant condition for static assertion 5 | static_assert(I{}.i); | ~~~~^ <source>:5:19: error: the value of '<anonymous>' is not usable in a constant expression <source>:5:17: note: '<anonymous>' was not declared 'constexpr' 5 | static_assert(I{}.i); | ^ Compiler returned: 1 ``` It works wrapped in an IILE, or if the `int` is uninitialized. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/106485] Can't use heap pointer in `static_assert` 2022-07-30 19:58 [Bug c++/106485] New: Can't use heap pointer in `static_assert` johelegp at gmail dot com @ 2022-07-30 22:16 ` pinskia at gcc dot gnu.org 2022-09-08 16:38 ` johelegp at gmail dot com ` (2 subsequent siblings) 3 siblings, 0 replies; 5+ messages in thread From: pinskia at gcc dot gnu.org @ 2022-07-30 22:16 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106485 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://gcc.gnu.org/bugzill | |a/show_bug.cgi?id=105826 --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- I think this is a dup of bug 105826. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/106485] Can't use heap pointer in `static_assert` 2022-07-30 19:58 [Bug c++/106485] New: Can't use heap pointer in `static_assert` johelegp at gmail dot com 2022-07-30 22:16 ` [Bug c++/106485] " pinskia at gcc dot gnu.org @ 2022-09-08 16:38 ` johelegp at gmail dot com 2023-01-19 1:36 ` pinskia at gcc dot gnu.org 2023-01-19 1:48 ` pinskia at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: johelegp at gmail dot com @ 2022-09-08 16:38 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106485 --- Comment #2 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> --- I think that's different. Actually, I think it's Clang that's wrong. As mentioned at https://cpplang.slack.com/archives/C21PKDHSL/p1656857369259539?thread_ts=1656856509.892079&cid=C21PKDHSL: > The expression of the `static_assert` is not an > [immediate function context](https://eel.is/c++draft/expr.const#def:immediate_function_context). > Wrapping it in `[]() consteval { return s().empty(); }()` [works](https://godbolt.org/z/PKTE7zofW), > whereas removing that `consteval` causes Clang to also complain. See https://godbolt.org/z/4GMxo13vv. ```C++ #include <string> consteval auto s() { return std::string(); } static_assert(s().empty()); // Only Clang accepts. // static_assert([]() consteval { return s().empty(); }()); // All accept. // static_assert([]() { return s().empty(); }()); // All reject. ``` Opened https://github.com/llvm/llvm-project/issues/57627 for that. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/106485] Can't use heap pointer in `static_assert` 2022-07-30 19:58 [Bug c++/106485] New: Can't use heap pointer in `static_assert` johelegp at gmail dot com 2022-07-30 22:16 ` [Bug c++/106485] " pinskia at gcc dot gnu.org 2022-09-08 16:38 ` johelegp at gmail dot com @ 2023-01-19 1:36 ` pinskia at gcc dot gnu.org 2023-01-19 1:48 ` pinskia at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: pinskia at gcc dot gnu.org @ 2023-01-19 1:36 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106485 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Status|UNCONFIRMED |NEW Last reconfirmed| |2023-01-19 --- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> --- I think comment #0 is a different issue from comment #2 really. comment #0 has a temporary while comment #2 has an consteval. Also GCC accepts this just fine though: #include <string> static_assert(!std::string{"abcdegfgggggggggggg"}.empty()); ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/106485] Can't use heap pointer in `static_assert` 2022-07-30 19:58 [Bug c++/106485] New: Can't use heap pointer in `static_assert` johelegp at gmail dot com ` (2 preceding siblings ...) 2023-01-19 1:36 ` pinskia at gcc dot gnu.org @ 2023-01-19 1:48 ` pinskia at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: pinskia at gcc dot gnu.org @ 2023-01-19 1:48 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106485 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |INVALID --- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Oh wait there comment #0 is still invalid (undefined?) code: ``` struct I { int* i = new int{1}; constexpr ~I() { delete i; } }; static_assert([] ()consteval { return I{}.i != 0; }()); ``` Works just fine. So yes this again is the same issue of static_assert not being immediate function context. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-01-19 1:48 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-07-30 19:58 [Bug c++/106485] New: Can't use heap pointer in `static_assert` johelegp at gmail dot com 2022-07-30 22:16 ` [Bug c++/106485] " pinskia at gcc dot gnu.org 2022-09-08 16:38 ` johelegp at gmail dot com 2023-01-19 1:36 ` pinskia at gcc dot gnu.org 2023-01-19 1:48 ` pinskia at gcc dot gnu.org
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).