public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/112744] New: Nested name specifier wrongly produces ambiguity in accessing static field
@ 2023-11-28 9:01 fchelnokov at gmail dot com
2023-11-28 19:22 ` [Bug c++/112744] " mpolacek at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: fchelnokov at gmail dot com @ 2023-11-28 9:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112744
Bug ID: 112744
Summary: Nested name specifier wrongly produces ambiguity in
accessing static field
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
struct A { constexpr static int a = 0; };
struct B : A {};
struct C : A {};
struct D : B, C {};
int main() {
(void)D{}.a; //ok everywhere
(void)D{}.A::a; //error in GCC
}
is accepted in Clang and MSVC, but GCC fails on the line with nested name
specifier:
error: 'A' is an ambiguous base of 'D'
Online demo: https://godbolt.org/z/vY6rjd9fx
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/112744] Nested name specifier wrongly produces ambiguity in accessing static field
2023-11-28 9:01 [Bug c++/112744] New: Nested name specifier wrongly produces ambiguity in accessing static field fchelnokov at gmail dot com
@ 2023-11-28 19:22 ` mpolacek at gcc dot gnu.org
2023-11-28 19:30 ` mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-11-28 19:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112744
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2023-11-28
CC| |mpolacek at gcc dot gnu.org
--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed, I think. Since a is static, there is only one copy. So it should
not matter that A is an ambiguous base of D (which it is). See [class]/note-3.
For the error line, in finish_class_member_access_expr scope will be A, so we
do
3496 /* Find the base of OBJECT_TYPE corresponding to SCOPE. */
3497 access_path = lookup_base (object_type, scope, ba_check,
3498 NULL, complain);
where object_type=D, scope=A. But the ba_check means we give an error.
We don't know at this point that name refers to a static data member. But we
can look it up, and maybe use ba_any.
Not a regression.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/112744] Nested name specifier wrongly produces ambiguity in accessing static field
2023-11-28 9:01 [Bug c++/112744] New: Nested name specifier wrongly produces ambiguity in accessing static field fchelnokov at gmail dot com
2023-11-28 19:22 ` [Bug c++/112744] " mpolacek at gcc dot gnu.org
@ 2023-11-28 19:30 ` mpolacek at gcc dot gnu.org
2023-11-30 21:42 ` cvs-commit at gcc dot gnu.org
2023-11-30 21:44 ` mpolacek at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-11-28 19:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112744
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
Status|NEW |ASSIGNED
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/112744] Nested name specifier wrongly produces ambiguity in accessing static field
2023-11-28 9:01 [Bug c++/112744] New: Nested name specifier wrongly produces ambiguity in accessing static field fchelnokov at gmail dot com
2023-11-28 19:22 ` [Bug c++/112744] " mpolacek at gcc dot gnu.org
2023-11-28 19:30 ` mpolacek at gcc dot gnu.org
@ 2023-11-30 21:42 ` cvs-commit at gcc dot gnu.org
2023-11-30 21:44 ` mpolacek at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-30 21:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112744
--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:725c68c54c265fe7f6fc7babff7139f3161bdfa6
commit r14-6024-g725c68c54c265fe7f6fc7babff7139f3161bdfa6
Author: Marek Polacek <polacek@redhat.com>
Date: Tue Nov 28 14:44:24 2023 -0500
c++: wrong ambiguity in accessing static field [PR112744]
Given
struct A { constexpr static int a = 0; };
struct B : A {};
struct C : A {};
struct D : B, C {};
we give the "'A' is an ambiguous base of 'D'" error for
D{}.A::a;
which seems wrong: 'a' is a static data member so there is only one copy
so it can be unambiguously referred to even if there are multiple A
objects. clang++/MSVC/icx agree.
This patch uses ba_any: [class.access.base] requires conversion to a unique
base subobject for non-static data members, but it does not require that
the
base be unique or accessible for static data members.
PR c++/112744
gcc/cp/ChangeLog:
* typeck.cc (finish_class_member_access_expr): When accessing
a static data member, use ba_any for lookup_base.
gcc/testsuite/ChangeLog:
* g++.dg/lookup/scoped11.C: New test.
* g++.dg/lookup/scoped12.C: New test.
* g++.dg/lookup/scoped13.C: New test.
* g++.dg/lookup/scoped14.C: New test.
* g++.dg/lookup/scoped15.C: New test.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/112744] Nested name specifier wrongly produces ambiguity in accessing static field
2023-11-28 9:01 [Bug c++/112744] New: Nested name specifier wrongly produces ambiguity in accessing static field fchelnokov at gmail dot com
` (2 preceding siblings ...)
2023-11-30 21:42 ` cvs-commit at gcc dot gnu.org
@ 2023-11-30 21:44 ` mpolacek at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-11-30 21:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112744
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed for GCC 14.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-11-30 21:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-28 9:01 [Bug c++/112744] New: Nested name specifier wrongly produces ambiguity in accessing static field fchelnokov at gmail dot com
2023-11-28 19:22 ` [Bug c++/112744] " mpolacek at gcc dot gnu.org
2023-11-28 19:30 ` mpolacek at gcc dot gnu.org
2023-11-30 21:42 ` cvs-commit at gcc dot gnu.org
2023-11-30 21:44 ` mpolacek 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).