https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123101
Bug ID: 123101
Summary: Parse error (instead of ambiguous symbol error) when
instantiating a template with an ambiguous symbol
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: b.stanimirov at abv dot bg
Target Milestone: ---
The issue is present on all versions since at least 13.3.0 on
The code fails with a parse error and no clue about the actual problem
(inner::foo is ambiguous):
```
namespace ns_a::inner {
struct foo {};
}
namespace ns_b::inner {
struct bar {};
}
template <typename T>
void func();
using namespace ns_a;
using namespace ns_b;
void test() {
func<ns_a::inner::foo>(); // works
// using foo = inner::foo; // ambiguous symbol
func<inner::foo>(); // parse error
}
```
Complete error message:
```
<source>: In function 'void test()':
<source>:18:5: error: parse error in template argument list
18 | func<inner::foo>(); // parse error
| ^~~~~~~~~~~~~~~~
<source>:18:21: error: no matching function for call to 'func<<expression
error> >()'
18 | func<inner::foo>(); // parse error
| ~~~~~~~~~~~~~~~~^~
• there is 1 candidate
• candidate 1: 'template<class T> void func()'
<source>:10:6:
10 | void func();
| ^~~~
• template argument deduction/substitution failed:
• error: template argument 1 is invalid
<source>:18:21:
18 | func<inner::foo>(); // parse error
| ~~~~~~~~~~~~~~~~^~
```
The expected behavior is to have an ambiguous symbol error as the one we get if
the the offending line is replaced with the commented one:
```
<source>: In function 'void test()':
<source>:17:17: error: reference to 'inner' is ambiguous
17 | using foo = inner::foo; // ambiguous symbol
| ^~~~~
<source>:5:17: note: candidates are: 'namespace ns_b::inner { }'
5 | namespace ns_b::inner {
| ^~~~~
<source>:1:17: note: 'namespace ns_a::inner { }'
1 | namespace ns_a::inner {
|
```
Live demo here: https://godbolt.org/z/GPoYv69Tq