Re: r268594 - Fix implementation of C++'s restrictions on using-declarations referring to enumerators:

2016-05-05 Thread Reid Kleckner via cfe-commits
FYI, this change broke bionic, which has this exact pattern:
https://android.googlesource.com/platform/bionic/+/master/tools/relocation_packer/src/debug.h#84

struct A {
  enum E {
X = 3
  };
};
typedef A::E T;
using T::X;

I expect users are going to have lots of issues with this, and it probably
warrants a release note.

On Wed, May 4, 2016 at 7:13 PM, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rsmith
> Date: Wed May  4 21:13:49 2016
> New Revision: 268594
>
> URL: http://llvm.org/viewvc/llvm-project?rev=268594&view=rev
> Log:
> Fix implementation of C++'s restrictions on using-declarations referring
> to enumerators:
>
>  * an unscoped enumerator whose enumeration is a class member is itself a
> class
>member, so can only be the subject of a class-scope using-declaration.
>
>  * a scoped enumerator cannot be the subject of a class-scope
> using-declaration.
>
> Added:
> cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p3.cpp
>   - copied, changed from r268583,
> cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p3-cxx0x.cpp
> cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p6-cxx11.cpp
>   - copied, changed from r268583,
> cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p6-cxx0x.cpp
> Removed:
> cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p3-cxx0x.cpp
> cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p6-cxx0x.cpp
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaDeclCXX.cpp
> cfe/trunk/test/CXX/drs/dr4xx.cpp
> cfe/trunk/test/SemaCXX/enum-scoped.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=268594&r1=268593&r2=268594&view=diff
>
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed May  4
> 21:13:49 2016
> @@ -396,7 +396,9 @@ def note_using_decl_class_member_workaro
>"use %select{an alias declaration|a typedef declaration|a reference}0 "
>"instead">;
>  def err_using_decl_can_not_refer_to_namespace : Error<
> -  "using declaration cannot refer to namespace">;
> +  "using declaration cannot refer to a namespace">;
> +def err_using_decl_can_not_refer_to_scoped_enum : Error<
> +  "using declaration cannot refer to a scoped enumerator">;
>  def err_using_decl_constructor : Error<
>"using declaration cannot refer to a constructor">;
>  def warn_cxx98_compat_using_decl_constructor : Warning<
>
> Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=268594&r1=268593&r2=268594&view=diff
>
> ==
> --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed May  4 21:13:49 2016
> @@ -7738,7 +7738,7 @@ bool Sema::CheckUsingShadowDecl(UsingDec
>// function will silently decide not to build a shadow decl, which
>// will pre-empt further diagnostics.
>//
> -  // We don't need to do this in C++0x because we do the check once on
> +  // We don't need to do this in C++11 because we do the check once on
>// the qualifier.
>//
>// FIXME: diagnose the following if we care enough:
> @@ -8227,7 +8227,7 @@ NamedDecl *Sema::BuildUsingDeclaration(S
>  }
>}
>
> -  // C++0x N2914 [namespace.udecl]p6:
> +  // C++14 [namespace.udecl]p6:
>// A using-declaration shall not name a namespace.
>if (R.getAsSingle()) {
>  Diag(IdentLoc, diag::err_using_decl_can_not_refer_to_namespace)
> @@ -8235,6 +8235,16 @@ NamedDecl *Sema::BuildUsingDeclaration(S
>  return BuildInvalid();
>}
>
> +  // C++14 [namespace.udecl]p7:
> +  // A using-declaration shall not name a scoped enumerator.
> +  if (auto *ED = R.getAsSingle()) {
> +if (cast(ED->getDeclContext())->isScoped()) {
> +  Diag(IdentLoc, diag::err_using_decl_can_not_refer_to_scoped_enum)
> +<< SS.getRange();
> +  return BuildInvalid();
> +}
> +  }
> +
>UsingDecl *UD = BuildValid();
>
>// The normal rules do not apply to inheriting constructor declarations.
> @@ -8359,8 +8369,10 @@ bool Sema::CheckUsingDeclQualifier(Sourc
>
>  // If we weren't able to compute a valid scope, it must be a
>  // dependent class scope.
> -if (!NamedContext || NamedContext->isRecord()) {
> -  auto *RD = dyn_cast_or_null(NamedContext);
> +if (!NamedContext || NamedContext->getRedeclContext()->isRecord()) {
> +  auto *RD = NamedContext
> + ?
> cast(NamedContext->getRedeclContext())
> + : nullptr;
>if (RD && RequireCompleteDeclContext(const_cast(SS),
> RD))
>  RD = nullptr;
>
> @@ -8444,7 +8456,7 

Re: r268594 - Fix implementation of C++'s restrictions on using-declarations referring to enumerators:

2016-05-05 Thread Richard Smith via cfe-commits
On Thu, May 5, 2016 at 10:40 AM, Reid Kleckner  wrote:

> FYI, this change broke bionic, which has this exact pattern:
>
> https://android.googlesource.com/platform/bionic/+/master/tools/relocation_packer/src/debug.h#84
>
> struct A {
>   enum E {
> X = 3
>   };
> };
> typedef A::E T;
> using T::X;
>
> I expect users are going to have lots of issues with this, and it probably
> warrants a release note.
>

Given that GCC rejects this code (and has done for as long as it's accepted
the Enum::Member syntax), I don't expect the problems to be too widespread.
If they are, we could trivially accept this as an extension; it seems like
a pointless restriction.


> On Wed, May 4, 2016 at 7:13 PM, Richard Smith via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: rsmith
>> Date: Wed May  4 21:13:49 2016
>> New Revision: 268594
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=268594&view=rev
>> Log:
>> Fix implementation of C++'s restrictions on using-declarations referring
>> to enumerators:
>>
>>  * an unscoped enumerator whose enumeration is a class member is itself a
>> class
>>member, so can only be the subject of a class-scope using-declaration.
>>
>>  * a scoped enumerator cannot be the subject of a class-scope
>> using-declaration.
>>
>> Added:
>> cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p3.cpp
>>   - copied, changed from r268583,
>> cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p3-cxx0x.cpp
>>
>> cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p6-cxx11.cpp
>>   - copied, changed from r268583,
>> cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p6-cxx0x.cpp
>> Removed:
>>
>> cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p3-cxx0x.cpp
>>
>> cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p6-cxx0x.cpp
>> Modified:
>> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> cfe/trunk/lib/Sema/SemaDeclCXX.cpp
>> cfe/trunk/test/CXX/drs/dr4xx.cpp
>> cfe/trunk/test/SemaCXX/enum-scoped.cpp
>>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=268594&r1=268593&r2=268594&view=diff
>>
>> ==
>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed May  4
>> 21:13:49 2016
>> @@ -396,7 +396,9 @@ def note_using_decl_class_member_workaro
>>"use %select{an alias declaration|a typedef declaration|a reference}0 "
>>"instead">;
>>  def err_using_decl_can_not_refer_to_namespace : Error<
>> -  "using declaration cannot refer to namespace">;
>> +  "using declaration cannot refer to a namespace">;
>> +def err_using_decl_can_not_refer_to_scoped_enum : Error<
>> +  "using declaration cannot refer to a scoped enumerator">;
>>  def err_using_decl_constructor : Error<
>>"using declaration cannot refer to a constructor">;
>>  def warn_cxx98_compat_using_decl_constructor : Warning<
>>
>> Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=268594&r1=268593&r2=268594&view=diff
>>
>> ==
>> --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed May  4 21:13:49 2016
>> @@ -7738,7 +7738,7 @@ bool Sema::CheckUsingShadowDecl(UsingDec
>>// function will silently decide not to build a shadow decl, which
>>// will pre-empt further diagnostics.
>>//
>> -  // We don't need to do this in C++0x because we do the check once on
>> +  // We don't need to do this in C++11 because we do the check once on
>>// the qualifier.
>>//
>>// FIXME: diagnose the following if we care enough:
>> @@ -8227,7 +8227,7 @@ NamedDecl *Sema::BuildUsingDeclaration(S
>>  }
>>}
>>
>> -  // C++0x N2914 [namespace.udecl]p6:
>> +  // C++14 [namespace.udecl]p6:
>>// A using-declaration shall not name a namespace.
>>if (R.getAsSingle()) {
>>  Diag(IdentLoc, diag::err_using_decl_can_not_refer_to_namespace)
>> @@ -8235,6 +8235,16 @@ NamedDecl *Sema::BuildUsingDeclaration(S
>>  return BuildInvalid();
>>}
>>
>> +  // C++14 [namespace.udecl]p7:
>> +  // A using-declaration shall not name a scoped enumerator.
>> +  if (auto *ED = R.getAsSingle()) {
>> +if (cast(ED->getDeclContext())->isScoped()) {
>> +  Diag(IdentLoc, diag::err_using_decl_can_not_refer_to_scoped_enum)
>> +<< SS.getRange();
>> +  return BuildInvalid();
>> +}
>> +  }
>> +
>>UsingDecl *UD = BuildValid();
>>
>>// The normal rules do not apply to inheriting constructor
>> declarations.
>> @@ -8359,8 +8369,10 @@ bool Sema::CheckUsingDeclQualifier(Sourc
>>
>>  // If we weren't able to compute a valid scope, it must be a
>>  // dependent class sc

Re: r268594 - Fix implementation of C++'s restrictions on using-declarations referring to enumerators:

2016-05-05 Thread Reid Kleckner via cfe-commits
On Thu, May 5, 2016 at 11:15 AM, Richard Smith 
wrote:

> Given that GCC rejects this code (and has done for as long as it's
> accepted the Enum::Member syntax), I don't expect the problems to be too
> widespread. If they are, we could trivially accept this as an extension; it
> seems like a pointless restriction.
>

I think there will be widespread issues on Mac, where many projects haven't
built with GCC in years.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r268594 - Fix implementation of C++'s restrictions on using-declarations referring to enumerators:

2016-05-05 Thread Richard Smith via cfe-commits
On Thu, May 5, 2016 at 11:21 AM, Reid Kleckner  wrote:

> On Thu, May 5, 2016 at 11:15 AM, Richard Smith 
> wrote:
>
>> Given that GCC rejects this code (and has done for as long as it's
>> accepted the Enum::Member syntax), I don't expect the problems to be too
>> widespread. If they are, we could trivially accept this as an extension; it
>> seems like a pointless restriction.
>>
>
> I think there will be widespread issues on Mac, where many projects
> haven't built with GCC in years.
>

I've added some release notes in r268663. If people complain that this is
breaking a significant amount of code, we can think about allowing this as
an extension.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits