| Summary: | An example from the standard regarding member lookup fails to compile | ||
|---|---|---|---|
| Product: | gcc | Reporter: | Ilya <ilaizi> |
| Component: | c++ | Assignee: | Not yet assigned to anyone <unassigned> |
| Status: | NEW --- | ||
| Severity: | normal | CC: | daniel.kruegler, mpolacek, niva, webrown.cpp |
| Priority: | P3 | Keywords: | rejects-valid |
| Version: | 6.1.0 | ||
| Target Milestone: | --- | ||
| See Also: | https://gcc.gnu.org/bugzilla/show_bug.cgi?id=31326 | ||
| Host: | Target: | ||
| Build: | Known to work: | ||
| Known to fail: | Last reconfirmed: | 2022-04-28 00:00:00 | |
| Bug Depends on: | |||
| Bug Blocks: | 12944 | ||
It's important to note that if you switch the order of inheritance in struct F
(
instead of: "struct F: public D, public E { };"
use: "struct F: public E, public F { };"
)
this example compiled without an error, even though the standard say that the order of derivation is not significant (10.1.2 Multiple base classes [class.mi])
|
Example of valid code from the standard (10.2.7 Member name lookup [class.member.lookup]) compiled with command: "g++ -std=c++11 main.cpp && ./a.out" on Linux compiler version: g++ (GCC) 6.1.0 Copyright (C) 2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. =================================================================================== struct A { int x; }; // S(x,A) = { { A::x }, { A } } struct B { float x; }; // S(x,B) = { { B::x }, { B } } struct C: public A, public B { }; // S(x,C) = { invalid, { A in C, B in C } } struct D: public virtual C { }; // S(x,D) = S(x,C) struct E: public virtual C { char x; }; // S(x,E) = { { E::x }, { E } } struct F: public D, public E { }; // S(x,F) = S(x,E) int main() { F f; f.x = 0; // OK, lookup finds E::x } =================================================================================== Error message: main.cpp: In function 'int main()': main.cpp:11:6: error: request for member 'x' is ambiguous f.x = 0; // OK, lookup finds E::x ^ main.cpp:2:18: note: candidates are: float B::x struct B { float x; }; // S(x,B) = { { B::x }, { B } } ^ main.cpp:1:16: note: int A::x struct A { int x; }; // S(x,A) = { { A::x }, { A } } ^