When a declaration is missing, the error returned by the compiler is too confusing. Consider the following short test case; namespace n { int var; //class foo { }; //template<typename T> class bar { }; } n::var x1; n::foo x3; n::bar<int> x4; The results in the following errors: test.cc:7: error: `var' in namespace `n' does not name a type test.cc:8: error: `foo' in namespace `n' does not name a type test.cc:9: error: expected constructor, destructor, or type conversion before '<' token test.cc:9: error: expected `,' or `;' before '<' token I'd like to suggest a different error for the case that there is no declaration at all (this could be tested after it is already detected that there is an error because foo is not a type): test.cc:8: error: `foo' in namespace `n' is not declared And of course, an improvement for templates. For example: test.cc:9: error: `bar' in namespace `n' is not declared
On second thought, make that: test.cc:8: error: `n::foo' has not been declared test.cc:9: error: `n::bar` has not been declared This is the same format that one gets when doing using n::foo; Note that the full namespace should be used - and not what is literally in the source. Consider: namespace n1 { namespace n2 { } } namespace n3 { namespace n2 { class foo { }; } } using namespace n1; n2::foo x; Then one wants: error: `n1::n2::foo' has not been declared
Confirmed, there might be another bug with the same problem.
In all three cases on the trunk we get: t.cc:7:1: error: ‘var’ in namespace ‘n’ does not name a type t.cc:8:1: error: ‘foo’ in namespace ‘n’ does not name a type t.cc:9:1: error: ‘bar’ in namespace ‘n’ does not name a type
In my opinion we are currently doing pretty well: the columns are ok; we handle templates with no excess error messages and we specifically talk about 'template type' for those. Comparing also to current clang, I think this bug could be closed. 16093.C:7:4: error: ‘var’ in namespace ‘n’ does not name a type n::var x1; ^ 16093.C:8:4: error: ‘foo’ in namespace ‘n’ does not name a type n::foo x3; ^ 16093.C:9:4: error: ‘bar’ in namespace ‘n’ does not name a template type n::bar<int> x4; ^
(In reply to Paolo Carlini from comment #4) > In my opinion we are currently doing pretty well: the columns are ok; we > handle templates with no excess error messages and we specifically talk > about 'template type' for those. Comparing also to current clang, I think > this bug could be closed. It has improved a lot yes. But I think the point of the original reporter is that g++ should make a difference between the case where 'foo' has not been declared in the current context or the case where 'var' has been declared but it is not a type. This way G++ could do *better* than clang. ;-) For the second testcase, we have also improved, since we print the full namespace, but clang has the helpful: test.cc:27:5: error: no type named 'foo' in namespace 'n1::n2'; did you mean 'n3::n2::foo'? But this is now a minor enhancement, not really a bug.
Honestly I didn't pay attention to the second testcase and didn't consider the first issue serious enough ;) Anyway, let's keep this open for now, thanks.
(In reply to Paolo Carlini from comment #6) > Honestly I didn't pay attention to the second testcase and didn't consider > the first issue serious enough ;) Anyway, let's keep this open for now, > thanks. The first issue is just a "nice-to-have" thing, but not very important. As for the second issue, it is already opened in a more general way at PR52277.
No change since 2013. I suspect that if this changes it will not be in response to this report but some other change so this might as well be resolved as good enough.