public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/113272] New: Wrong specialization of class template selected @ 2024-01-08 13:23 fchelnokov at gmail dot com 2024-01-08 15:52 ` [Bug c++/113272] " pinskia at gcc dot gnu.org ` (3 more replies) 0 siblings, 4 replies; 5+ messages in thread From: fchelnokov at gmail dot com @ 2024-01-08 13:23 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113272 Bug ID: 113272 Summary: Wrong specialization of class template selected Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: fchelnokov at gmail dot com Target Milestone: --- This program #include <concepts> template <auto> struct A; template <auto p> requires std::same_as<decltype(p), const int*> struct A<p> : std::false_type {}; template <auto p> requires std::same_as<decltype(p), int*> struct A<p> : std::true_type {}; int x = 0; static_assert( A<&x>::value ); ///< try to comment this line static_assert( !A<(const int *)&x>::value ); ///< GCC fails here is accepted by Clang and MSVC, but GCC erroneously evaluates the last line. Online demo: https://godbolt.org/z/5Pqx6TG3W But if one comments the previous static_assert, then it starts working. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/113272] Wrong specialization of class template selected 2024-01-08 13:23 [Bug c++/113272] New: Wrong specialization of class template selected fchelnokov at gmail dot com @ 2024-01-08 15:52 ` pinskia at gcc dot gnu.org 2024-01-09 14:41 ` mpolacek at gcc dot gnu.org ` (2 subsequent siblings) 3 siblings, 0 replies; 5+ messages in thread From: pinskia at gcc dot gnu.org @ 2024-01-08 15:52 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113272 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |janschultke at googlemail dot com --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- *** Bug 113274 has been marked as a duplicate of this bug. *** ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/113272] Wrong specialization of class template selected 2024-01-08 13:23 [Bug c++/113272] New: Wrong specialization of class template selected fchelnokov at gmail dot com 2024-01-08 15:52 ` [Bug c++/113272] " pinskia at gcc dot gnu.org @ 2024-01-09 14:41 ` mpolacek at gcc dot gnu.org 2024-01-09 14:56 ` fchelnokov at gmail dot com 2024-01-10 0:12 ` pinskia at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: mpolacek at gcc dot gnu.org @ 2024-01-09 14:41 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113272 Marek Polacek <mpolacek at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2024-01-09 CC| |mpolacek at gcc dot gnu.org Ever confirmed|0 |1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/113272] Wrong specialization of class template selected 2024-01-08 13:23 [Bug c++/113272] New: Wrong specialization of class template selected fchelnokov at gmail dot com 2024-01-08 15:52 ` [Bug c++/113272] " pinskia at gcc dot gnu.org 2024-01-09 14:41 ` mpolacek at gcc dot gnu.org @ 2024-01-09 14:56 ` fchelnokov at gmail dot com 2024-01-10 0:12 ` pinskia at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: fchelnokov at gmail dot com @ 2024-01-09 14:56 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113272 --- Comment #2 from Fedor Chelnokov <fchelnokov at gmail dot com> --- Here is simplified program without #include <concepts>: template <auto> struct A {}; template <auto p> requires requires(){ *p = 0; } struct A<p> {}; int x = 0; struct B : A<&x>, A<(const int *)&x> {}; GCC fails here because of error: duplicate base type 'A<(& x)>' invalid Online demo: https://godbolt.org/z/aan59E6WE ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/113272] Wrong specialization of class template selected 2024-01-08 13:23 [Bug c++/113272] New: Wrong specialization of class template selected fchelnokov at gmail dot com ` (2 preceding siblings ...) 2024-01-09 14:56 ` fchelnokov at gmail dot com @ 2024-01-10 0:12 ` pinskia at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: pinskia at gcc dot gnu.org @ 2024-01-10 0:12 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113272 --- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Ok, this behavior is interesting: ``` int g = 0; int g1 = 0; template <auto *a> struct A { void f() { g++; } }; template < const auto * a> struct A<a>{ void f(){ g1++; } }; int x = 0; const int x1 = 0; int main() { { int t = 0; A<&x> a; t++; a.f(); if (g != t) return 1; } int t = 0; if (0){ A<(const int *)&x> a1; a1.f(); t++; if (g1 != t) return 1; } { A<&x1> a1; a1.f(); t++; if (g1 != t) return 1; } return 0; } ``` The above passes like expected but if we enable the case for `A<(const int *)&x>`, we get a failure in that g is incremented and not g1. Note MSVC has the same behavior for the above testcase. Though clang rejects it with an error: ``` <source>:9:8: error: class template partial specialization is not more specialized than the primary template [-Winvalid-partial-specialization] 9 | struct A<a>{ | ^ <source>:4:8: note: template is declared here 4 | struct A { | ^ ``` Which I find even more interesting ... ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-01-10 0:12 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-01-08 13:23 [Bug c++/113272] New: Wrong specialization of class template selected fchelnokov at gmail dot com 2024-01-08 15:52 ` [Bug c++/113272] " pinskia at gcc dot gnu.org 2024-01-09 14:41 ` mpolacek at gcc dot gnu.org 2024-01-09 14:56 ` fchelnokov at gmail dot com 2024-01-10 0:12 ` 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).