This is an archive of the discontinued LLVM Phabricator instance.

Provide fixit if unscoped enumeration is used in nested name specifier. This fixes PR16951.
ClosedPublic

Authored by sepavloff on Nov 24 2014, 11:08 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

sepavloff updated this revision to Diff 16572.Nov 24 2014, 11:08 AM
sepavloff retitled this revision from to Provide fixit if unscoped enumeration is used in nested name specifier. This fixes PR16951..
sepavloff updated this object.
sepavloff edited the test plan for this revision. (Show Details)
sepavloff added a subscriber: Unknown Object (MLST).
sepavloff updated this revision to Diff 17972.Jan 10 2015, 4:50 AM

Updated patch to address reviewer's notes. Added handling of Microsoft extension.

rsmith requested changes to this revision.Jan 14 2015, 5:36 PM
rsmith added a reviewer: rsmith.
rsmith added a subscriber: rsmith.

This patch does not seem to be correct. Using an enumerator as a nested-name-specifier is a C++11 extension. MSVC enables C++11 by default. The only bug I can see here is that our diagnostic is misworded: in C++11, we should say "%0 is not a class, namespace, or enumeration" (remove the word "scoped"), and in C++98, we should say "%0 is not a class or namespace"

This revision now requires changes to proceed.Jan 14 2015, 5:36 PM

MSVC supported using an enumerator as a nested-name-specifier for a long time. For instance, VS2005 compiled the code:

enum ABCD { A, B, C };

int main() {
  return ABCD::A;
}

without errors:

C:\Tools>cl tt.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

tt.cpp
tt.cpp(4) : warning C4482: nonstandard extension used: enum 'ABCD' used in qualified name
Microsoft (R) Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:tt.exe
tt.obj

C:\Tools>

VS2010 compiles this code without warnings by default. It is reasonable to accept this code in Microsoft mode without warnings by default, isn't it?

However, complaining on using extension make the patch simpler, will update it.

sepavloff updated this revision to Diff 18311.Jan 16 2015, 12:42 PM
sepavloff edited edge metadata.

Updated patch.

Instead of providing removal fixit, issue extension warning.

rsmith accepted this revision.Jan 16 2015, 6:04 PM
rsmith edited edge metadata.

LGTM with a couple of tweaks. (We should also fix the "is not a class, namespace, or scoped enumeration" diagnostic to remove the word "scoped", feel free to go ahead and commit a patch for that.)

include/clang/Basic/DiagnosticSemaKinds.td
1232 ↗(On Diff #18311)

Remove the "unscoped" here. C++98 didn't have scoped enumerations, and in any case, this diagnostic is not specific to unscoped enumerations.

lib/Sema/SemaCXXScopeSpec.cpp
286–287 ↗(On Diff #18311)

s/may be used in extended syntax/is accepted as an extension/

This revision is now accepted and ready to land.Jan 16 2015, 6:04 PM
This revision was automatically updated to reflect the committed changes.