C++ Logo

std-proposals

Advanced search

Re: Allow use of constants and types from not-instantiation-ed template

From: Hani Deek <hani_deek_at_[hidden]>
Date: Mon, 20 Dec 2021 22:49:17 +0000
> I'd like to understand more how the modified name lookup rules are
> supposed to work, with special attention to backward compatibility
> concerns, i.e. how existing code might change meaning under the new
> rules.

I have not developed a full proposal. What I say here are just preliminary thoughts.
We may introduce a rule whereby an ambiguous name 'Foo' (that names both a namespace and a class template) will be considered a namespace name in contexts where it cannot be a template name, e.g. if it is followed by :: and not possibly an injected class name. In other contexts, Foo will be considered a template name or an injected class name, per the current rules.
That rule should not cause backward compatibility issues.
Internally, the compiler can assign different names to the namespace Foo and the class template Foo.

Like I said, I don't think such rules can be adopted.

If someone will make a proposal of this sort, the proposal should aim to do more important things, such as ridding us of the unnecessary 'template' keyword with dependent names.

I believe that the vast majority of cases where a dependent name is currently required to be preceded by 'template' do not really require the use of that keyword.

Consider the following:

template<typename>
struct A;

template<typename T>
auto foo() { return A<T>::B<int>; }

What are the chances that 'B' is not a template name? The answer is zero. There is no way that 'B' in this case is not a template name. The operator < cannot have 'int' or any other type name as an operand.

But C++ requires us to use the keyword 'template' before B<int> because of alleged ambiguity.

I believe it is more important to address those simple issues before we try to go further and introduce things like the proposal I wrote above.

I doubt that such proposals can be adopted, because C++ seems to be built around the concept that the compiler will generally not try to disambiguate names based on their context. Instead, the user should provide an unambiguous name and the compiler will then check if the context is valid for the use of that name.

Received on 2021-12-20 16:49:28