llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.8k stars 11.9k forks source link

Allows using-declaration to refer to scoped enumerator #9496

Closed be579e8c-b74b-475b-a126-3b8cefdd833c closed 12 months ago

be579e8c-b74b-475b-a126-3b8cefdd833c commented 13 years ago
Bugzilla Link 9124
Version trunk
OS Linux
CC @DougGregor,@gnzlbg,@zygoloid

Extended Description

Clang is supposed to reject the below, but doesn't

enum class A { B };
int main() {
  using A::B; // should be an error
}

Although the spec (N3225) doesn't say so currently (DR already filed), clang should presumably also reject referring to an unscoped enumerator in a using declaration:

enum A { B };
int main() {
  using A::B; // presumably should be error too. 
}

I think best may be to forbid the using declaration of having a nested name specifier referring to an enumeration.

54aefcd4-c07d-4252-8441-723563c8826f commented 8 years ago

FWIW with inline variables:

static constexpr auto B = A::B;

Is safe and does the right thing.

While I would like "using A::B" to work, I would rather warn on this until this is allowed by the standard.

be579e8c-b74b-475b-a126-3b8cefdd833c commented 12 years ago

Of couse we cannot straight out forbid referring to a unscoped enumerator because it needs still to be allowed as a member declaration if the NNS is a class.

be579e8c-b74b-475b-a126-3b8cefdd833c commented 12 years ago

I sent this issue to WMM twice with a year of distance between each iteration, but he did not respond -.- So there is no DR# yet.

Hello Mike,

7.3.3p7 says

A /using-declaration/ shall not name a scoped enumerator.

Presumably, this is intended to forbid the following case too.

enum A { B }; void f() { using A::B; }

However, A::B is an unscoped enumerator according to 7.2p2. It should probably forbid the nested-name-specifier of the using-declaration to name an enumeration, instead.

Thanks, Johannes.

ec04fc15-fa35-46f2-80e1-5d271f2ef708 commented 12 years ago

[namespace.udecl]p7 is clear that we should diagnose this, but it's not obvious why. The functionality is useful and doesn't have any obvious semantic issues.

Johannes: Do you have a DR# for this? I couldn't find it in the issues list, and I'd like to suggest a different resolution :)

llvmbot commented 12 months ago

@llvm/issue-subscribers-clang-frontend

Author: None (be579e8c-b74b-475b-a126-3b8cefdd833c)

| | | | --- | --- | | Bugzilla Link | [9124](https://llvm.org/bz9124) | | Version | trunk | | OS | Linux | | CC | @DougGregor,@gnzlbg,@zygoloid | ## Extended Description Clang is supposed to reject the below, but doesn't enum class A { B }; int main() { using A::B; // should be an error } Although the spec (N3225) doesn't say so currently (DR already filed), clang should presumably also reject referring to an unscoped enumerator in a using declaration: enum A { B }; int main() { using A::B; // presumably should be error too. } I think best may be to forbid the using declaration of having a nested name specifier referring to an enumeration.
shafik commented 12 months ago

There are both valid and accepted by all the implementations I checked.