Re: [clang] 0e3a487 - PR12350: Handle remaining cases permitted by CWG DR 244.

2020-11-06 Thread Richard Smith via cfe-commits
On Fri, 6 Nov 2020 at 13:30, Alex L  wrote:

> Hi Rchard,
>
> Some of our code started triggering the warning you added in this code,
> but I'm not sure if the warning is actually valid or not in this case:
>
> https://godbolt.org/z/9fxs3K
>
> namespace geo {
>   template
> class optional {
> optional() { }
> ~optional();
> };
> }
> template
> geo::optional::~optional() // Triggers  ISO C++ requires the name after
> '::~' to be found in the same scope as the name before '::~'
> {
> }
>
> Could you confirm whether or not this warning is valid for our code?
>

Technically, yes, the warning is correct; the C++ rules require that to be
written as

geo::optional::~optional()

... but of course no-one does that, and it doesn't seem to be an intended
restriction. I've been working with the C++ committee to get the language
rule fixed, and the fix will be in P1787R6, which is due to be voted into
C++23 (with at least this part as a DR against prior standards) next week.
It's probably time to implement the new rule :)

In the meantime, using -Wno-dtor-name would be reasonable.


> Thanks,
> Alex
>
>
> On Thu, 13 Feb 2020 at 00:52, Richard Smith via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Thanks, yes, fixed in llvmorg-11-init-3043-gc1394afb8df.
>>
>> On Thu, 13 Feb 2020 at 02:58, Kostya Serebryany via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Could this have caused a new ubsan failure?
>>>
>>> clang/lib/AST/NestedNameSpecifier.cpp:485:23: runtime error: null pointer 
>>> passed as argument 2, which is declared to never be null
>>>
>>>
>>> http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/38698/steps/check-clang%20ubsan/logs/stdio
>>>
>>> On Fri, Feb 7, 2020 at 6:41 PM Richard Smith via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>

 Author: Richard Smith
 Date: 2020-02-07T18:40:41-08:00
 New Revision: 0e3a48778408b505946e465abf5c77a2ddd4918c

 URL:
 https://github.com/llvm/llvm-project/commit/0e3a48778408b505946e465abf5c77a2ddd4918c
 DIFF:
 https://github.com/llvm/llvm-project/commit/0e3a48778408b505946e465abf5c77a2ddd4918c.diff

 LOG: PR12350: Handle remaining cases permitted by CWG DR 244.

 Also add extension warnings for the cases that are disallowed by the
 current rules for destructor name lookup, refactor and simplify the
 lookup code, and improve the diagnostic quality when lookup fails.

 The special case we previously supported for converting
 p->N::S::~S() from naming a class template into naming a
 specialization thereof is subsumed by a more general rule here (which is
 also consistent with Clang's historical behavior and that of other
 compilers): if we can't find a suitable S in N, also look in N::S.

 The extension warnings are off by default, except for a warning when
 lookup for p->N::S::~T() looks for T in scope instead of in N (or N::S).
 That seems sufficiently heinous to warn on by default, especially since
 we can't support it for a dependent nested-name-specifier.

 Added:


 Modified:
 clang/include/clang/Basic/DiagnosticGroups.td
 clang/include/clang/Basic/DiagnosticSemaKinds.td
 clang/lib/AST/NestedNameSpecifier.cpp
 clang/lib/Sema/DeclSpec.cpp
 clang/lib/Sema/SemaExprCXX.cpp
 clang/test/CXX/class/class.mem/p13.cpp
 clang/test/CXX/drs/dr2xx.cpp
 clang/test/CXX/drs/dr3xx.cpp
 clang/test/FixIt/fixit.cpp
 clang/test/Parser/cxx-decl.cpp
 clang/test/SemaCXX/constructor.cpp
 clang/test/SemaCXX/destructor.cpp
 clang/test/SemaCXX/pseudo-destructors.cpp

 Removed:




 
 diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td
 b/clang/include/clang/Basic/DiagnosticGroups.td
 index a2bc29986a07..8c54723cdbab 100644
 --- a/clang/include/clang/Basic/DiagnosticGroups.td
 +++ b/clang/include/clang/Basic/DiagnosticGroups.td
 @@ -192,6 +192,7 @@ def CXX2aDesignator : DiagGroup<"c++2a-designator">;
  // designators (including the warning controlled by
 -Wc++2a-designator).
  def C99Designator : DiagGroup<"c99-designator", [CXX2aDesignator]>;
  def GNUDesignator : DiagGroup<"gnu-designator">;
 +def DtorName : DiagGroup<"dtor-name">;

  def DynamicExceptionSpec
  : DiagGroup<"dynamic-exception-spec",
 [DeprecatedDynamicExceptionSpec]>;

 diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td
 b/clang/include/clang/Basic/DiagnosticSemaKinds.td
 index 9de60d3a8d27..82861f0d5d72 100644
 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
 +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
 @@ -1911,17 +1911,33 @@ def err_destructor_with_params :
 Error<"destructor cannot have any parameters">;
  

Re: [clang] 0e3a487 - PR12350: Handle remaining cases permitted by CWG DR 244.

2020-11-06 Thread Alex L via cfe-commits
Hi Rchard,

Some of our code started triggering the warning you added in this code, but
I'm not sure if the warning is actually valid or not in this case:

https://godbolt.org/z/9fxs3K

namespace geo {
  template
class optional {
optional() { }
~optional();
};
}
template
geo::optional::~optional() // Triggers  ISO C++ requires the name after
'::~' to be found in the same scope as the name before '::~'
{
}

Could you confirm whether or not this warning is valid for our code?

Thanks,
Alex


On Thu, 13 Feb 2020 at 00:52, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Thanks, yes, fixed in llvmorg-11-init-3043-gc1394afb8df.
>
> On Thu, 13 Feb 2020 at 02:58, Kostya Serebryany via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Could this have caused a new ubsan failure?
>>
>> clang/lib/AST/NestedNameSpecifier.cpp:485:23: runtime error: null pointer 
>> passed as argument 2, which is declared to never be null
>>
>>
>> http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/38698/steps/check-clang%20ubsan/logs/stdio
>>
>> On Fri, Feb 7, 2020 at 6:41 PM Richard Smith via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>>
>>> Author: Richard Smith
>>> Date: 2020-02-07T18:40:41-08:00
>>> New Revision: 0e3a48778408b505946e465abf5c77a2ddd4918c
>>>
>>> URL:
>>> https://github.com/llvm/llvm-project/commit/0e3a48778408b505946e465abf5c77a2ddd4918c
>>> DIFF:
>>> https://github.com/llvm/llvm-project/commit/0e3a48778408b505946e465abf5c77a2ddd4918c.diff
>>>
>>> LOG: PR12350: Handle remaining cases permitted by CWG DR 244.
>>>
>>> Also add extension warnings for the cases that are disallowed by the
>>> current rules for destructor name lookup, refactor and simplify the
>>> lookup code, and improve the diagnostic quality when lookup fails.
>>>
>>> The special case we previously supported for converting
>>> p->N::S::~S() from naming a class template into naming a
>>> specialization thereof is subsumed by a more general rule here (which is
>>> also consistent with Clang's historical behavior and that of other
>>> compilers): if we can't find a suitable S in N, also look in N::S.
>>>
>>> The extension warnings are off by default, except for a warning when
>>> lookup for p->N::S::~T() looks for T in scope instead of in N (or N::S).
>>> That seems sufficiently heinous to warn on by default, especially since
>>> we can't support it for a dependent nested-name-specifier.
>>>
>>> Added:
>>>
>>>
>>> Modified:
>>> clang/include/clang/Basic/DiagnosticGroups.td
>>> clang/include/clang/Basic/DiagnosticSemaKinds.td
>>> clang/lib/AST/NestedNameSpecifier.cpp
>>> clang/lib/Sema/DeclSpec.cpp
>>> clang/lib/Sema/SemaExprCXX.cpp
>>> clang/test/CXX/class/class.mem/p13.cpp
>>> clang/test/CXX/drs/dr2xx.cpp
>>> clang/test/CXX/drs/dr3xx.cpp
>>> clang/test/FixIt/fixit.cpp
>>> clang/test/Parser/cxx-decl.cpp
>>> clang/test/SemaCXX/constructor.cpp
>>> clang/test/SemaCXX/destructor.cpp
>>> clang/test/SemaCXX/pseudo-destructors.cpp
>>>
>>> Removed:
>>>
>>>
>>>
>>>
>>> 
>>> diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td
>>> b/clang/include/clang/Basic/DiagnosticGroups.td
>>> index a2bc29986a07..8c54723cdbab 100644
>>> --- a/clang/include/clang/Basic/DiagnosticGroups.td
>>> +++ b/clang/include/clang/Basic/DiagnosticGroups.td
>>> @@ -192,6 +192,7 @@ def CXX2aDesignator : DiagGroup<"c++2a-designator">;
>>>  // designators (including the warning controlled by -Wc++2a-designator).
>>>  def C99Designator : DiagGroup<"c99-designator", [CXX2aDesignator]>;
>>>  def GNUDesignator : DiagGroup<"gnu-designator">;
>>> +def DtorName : DiagGroup<"dtor-name">;
>>>
>>>  def DynamicExceptionSpec
>>>  : DiagGroup<"dynamic-exception-spec",
>>> [DeprecatedDynamicExceptionSpec]>;
>>>
>>> diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td
>>> b/clang/include/clang/Basic/DiagnosticSemaKinds.td
>>> index 9de60d3a8d27..82861f0d5d72 100644
>>> --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
>>> +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
>>> @@ -1911,17 +1911,33 @@ def err_destructor_with_params :
>>> Error<"destructor cannot have any parameters">;
>>>  def err_destructor_variadic : Error<"destructor cannot be variadic">;
>>>  def err_destructor_typedef_name : Error<
>>>"destructor cannot be declared using a %select{typedef|type alias}1
>>> %0 of the class name">;
>>> +def err_undeclared_destructor_name : Error<
>>> +  "undeclared identifier %0 in destructor name">;
>>>  def err_destructor_name : Error<
>>>"expected the class name after '~' to name the enclosing class">;
>>> -def err_destructor_class_name : Error<
>>> -  "expected the class name after '~' to name a destructor">;
>>> -def err_ident_in_dtor_not_a_type : Error<
>>> +def err_destructor_name_nontype : Error<
>>> +  "identifier %0 after '~' in destructor name does not name a type">;
>>> 

Re: [clang] 0e3a487 - PR12350: Handle remaining cases permitted by CWG DR 244.

2020-02-13 Thread Richard Smith via cfe-commits
Thanks, yes, fixed in llvmorg-11-init-3043-gc1394afb8df.

On Thu, 13 Feb 2020 at 02:58, Kostya Serebryany via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Could this have caused a new ubsan failure?
>
> clang/lib/AST/NestedNameSpecifier.cpp:485:23: runtime error: null pointer 
> passed as argument 2, which is declared to never be null
>
>
> http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/38698/steps/check-clang%20ubsan/logs/stdio
>
> On Fri, Feb 7, 2020 at 6:41 PM Richard Smith via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>>
>> Author: Richard Smith
>> Date: 2020-02-07T18:40:41-08:00
>> New Revision: 0e3a48778408b505946e465abf5c77a2ddd4918c
>>
>> URL:
>> https://github.com/llvm/llvm-project/commit/0e3a48778408b505946e465abf5c77a2ddd4918c
>> DIFF:
>> https://github.com/llvm/llvm-project/commit/0e3a48778408b505946e465abf5c77a2ddd4918c.diff
>>
>> LOG: PR12350: Handle remaining cases permitted by CWG DR 244.
>>
>> Also add extension warnings for the cases that are disallowed by the
>> current rules for destructor name lookup, refactor and simplify the
>> lookup code, and improve the diagnostic quality when lookup fails.
>>
>> The special case we previously supported for converting
>> p->N::S::~S() from naming a class template into naming a
>> specialization thereof is subsumed by a more general rule here (which is
>> also consistent with Clang's historical behavior and that of other
>> compilers): if we can't find a suitable S in N, also look in N::S.
>>
>> The extension warnings are off by default, except for a warning when
>> lookup for p->N::S::~T() looks for T in scope instead of in N (or N::S).
>> That seems sufficiently heinous to warn on by default, especially since
>> we can't support it for a dependent nested-name-specifier.
>>
>> Added:
>>
>>
>> Modified:
>> clang/include/clang/Basic/DiagnosticGroups.td
>> clang/include/clang/Basic/DiagnosticSemaKinds.td
>> clang/lib/AST/NestedNameSpecifier.cpp
>> clang/lib/Sema/DeclSpec.cpp
>> clang/lib/Sema/SemaExprCXX.cpp
>> clang/test/CXX/class/class.mem/p13.cpp
>> clang/test/CXX/drs/dr2xx.cpp
>> clang/test/CXX/drs/dr3xx.cpp
>> clang/test/FixIt/fixit.cpp
>> clang/test/Parser/cxx-decl.cpp
>> clang/test/SemaCXX/constructor.cpp
>> clang/test/SemaCXX/destructor.cpp
>> clang/test/SemaCXX/pseudo-destructors.cpp
>>
>> Removed:
>>
>>
>>
>>
>> 
>> diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td
>> b/clang/include/clang/Basic/DiagnosticGroups.td
>> index a2bc29986a07..8c54723cdbab 100644
>> --- a/clang/include/clang/Basic/DiagnosticGroups.td
>> +++ b/clang/include/clang/Basic/DiagnosticGroups.td
>> @@ -192,6 +192,7 @@ def CXX2aDesignator : DiagGroup<"c++2a-designator">;
>>  // designators (including the warning controlled by -Wc++2a-designator).
>>  def C99Designator : DiagGroup<"c99-designator", [CXX2aDesignator]>;
>>  def GNUDesignator : DiagGroup<"gnu-designator">;
>> +def DtorName : DiagGroup<"dtor-name">;
>>
>>  def DynamicExceptionSpec
>>  : DiagGroup<"dynamic-exception-spec",
>> [DeprecatedDynamicExceptionSpec]>;
>>
>> diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td
>> b/clang/include/clang/Basic/DiagnosticSemaKinds.td
>> index 9de60d3a8d27..82861f0d5d72 100644
>> --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
>> +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
>> @@ -1911,17 +1911,33 @@ def err_destructor_with_params :
>> Error<"destructor cannot have any parameters">;
>>  def err_destructor_variadic : Error<"destructor cannot be variadic">;
>>  def err_destructor_typedef_name : Error<
>>"destructor cannot be declared using a %select{typedef|type alias}1 %0
>> of the class name">;
>> +def err_undeclared_destructor_name : Error<
>> +  "undeclared identifier %0 in destructor name">;
>>  def err_destructor_name : Error<
>>"expected the class name after '~' to name the enclosing class">;
>> -def err_destructor_class_name : Error<
>> -  "expected the class name after '~' to name a destructor">;
>> -def err_ident_in_dtor_not_a_type : Error<
>> +def err_destructor_name_nontype : Error<
>> +  "identifier %0 after '~' in destructor name does not name a type">;
>> +def err_destructor_expr_mismatch : Error<
>> +  "identifier %0 in object destruction expression does not name the type
>> "
>> +  "%1 of the object being destroyed">;
>> +def err_destructor_expr_nontype : Error<
>>"identifier %0 in object destruction expression does not name a type">;
>>  def err_destructor_expr_type_mismatch : Error<
>>"destructor type %0 in object destruction expression does not match
>> the "
>>"type %1 of the object being destroyed">;
>>  def note_destructor_type_here : Note<
>> -  "type %0 is declared here">;
>> +  "type %0 found by destructor name lookup">;
>> +def note_destructor_nontype_here : Note<
>> +  "non-type declaration found by destructor name 

Re: [clang] 0e3a487 - PR12350: Handle remaining cases permitted by CWG DR 244.

2020-02-12 Thread Kostya Serebryany via cfe-commits
Could this have caused a new ubsan failure?

clang/lib/AST/NestedNameSpecifier.cpp:485:23: runtime error: null
pointer passed as argument 2, which is declared to never be null

http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/38698/steps/check-clang%20ubsan/logs/stdio

On Fri, Feb 7, 2020 at 6:41 PM Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

>
> Author: Richard Smith
> Date: 2020-02-07T18:40:41-08:00
> New Revision: 0e3a48778408b505946e465abf5c77a2ddd4918c
>
> URL:
> https://github.com/llvm/llvm-project/commit/0e3a48778408b505946e465abf5c77a2ddd4918c
> DIFF:
> https://github.com/llvm/llvm-project/commit/0e3a48778408b505946e465abf5c77a2ddd4918c.diff
>
> LOG: PR12350: Handle remaining cases permitted by CWG DR 244.
>
> Also add extension warnings for the cases that are disallowed by the
> current rules for destructor name lookup, refactor and simplify the
> lookup code, and improve the diagnostic quality when lookup fails.
>
> The special case we previously supported for converting
> p->N::S::~S() from naming a class template into naming a
> specialization thereof is subsumed by a more general rule here (which is
> also consistent with Clang's historical behavior and that of other
> compilers): if we can't find a suitable S in N, also look in N::S.
>
> The extension warnings are off by default, except for a warning when
> lookup for p->N::S::~T() looks for T in scope instead of in N (or N::S).
> That seems sufficiently heinous to warn on by default, especially since
> we can't support it for a dependent nested-name-specifier.
>
> Added:
>
>
> Modified:
> clang/include/clang/Basic/DiagnosticGroups.td
> clang/include/clang/Basic/DiagnosticSemaKinds.td
> clang/lib/AST/NestedNameSpecifier.cpp
> clang/lib/Sema/DeclSpec.cpp
> clang/lib/Sema/SemaExprCXX.cpp
> clang/test/CXX/class/class.mem/p13.cpp
> clang/test/CXX/drs/dr2xx.cpp
> clang/test/CXX/drs/dr3xx.cpp
> clang/test/FixIt/fixit.cpp
> clang/test/Parser/cxx-decl.cpp
> clang/test/SemaCXX/constructor.cpp
> clang/test/SemaCXX/destructor.cpp
> clang/test/SemaCXX/pseudo-destructors.cpp
>
> Removed:
>
>
>
>
> 
> diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td
> b/clang/include/clang/Basic/DiagnosticGroups.td
> index a2bc29986a07..8c54723cdbab 100644
> --- a/clang/include/clang/Basic/DiagnosticGroups.td
> +++ b/clang/include/clang/Basic/DiagnosticGroups.td
> @@ -192,6 +192,7 @@ def CXX2aDesignator : DiagGroup<"c++2a-designator">;
>  // designators (including the warning controlled by -Wc++2a-designator).
>  def C99Designator : DiagGroup<"c99-designator", [CXX2aDesignator]>;
>  def GNUDesignator : DiagGroup<"gnu-designator">;
> +def DtorName : DiagGroup<"dtor-name">;
>
>  def DynamicExceptionSpec
>  : DiagGroup<"dynamic-exception-spec",
> [DeprecatedDynamicExceptionSpec]>;
>
> diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td
> b/clang/include/clang/Basic/DiagnosticSemaKinds.td
> index 9de60d3a8d27..82861f0d5d72 100644
> --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
> +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
> @@ -1911,17 +1911,33 @@ def err_destructor_with_params : Error<"destructor
> cannot have any parameters">;
>  def err_destructor_variadic : Error<"destructor cannot be variadic">;
>  def err_destructor_typedef_name : Error<
>"destructor cannot be declared using a %select{typedef|type alias}1 %0
> of the class name">;
> +def err_undeclared_destructor_name : Error<
> +  "undeclared identifier %0 in destructor name">;
>  def err_destructor_name : Error<
>"expected the class name after '~' to name the enclosing class">;
> -def err_destructor_class_name : Error<
> -  "expected the class name after '~' to name a destructor">;
> -def err_ident_in_dtor_not_a_type : Error<
> +def err_destructor_name_nontype : Error<
> +  "identifier %0 after '~' in destructor name does not name a type">;
> +def err_destructor_expr_mismatch : Error<
> +  "identifier %0 in object destruction expression does not name the type "
> +  "%1 of the object being destroyed">;
> +def err_destructor_expr_nontype : Error<
>"identifier %0 in object destruction expression does not name a type">;
>  def err_destructor_expr_type_mismatch : Error<
>"destructor type %0 in object destruction expression does not match the
> "
>"type %1 of the object being destroyed">;
>  def note_destructor_type_here : Note<
> -  "type %0 is declared here">;
> +  "type %0 found by destructor name lookup">;
> +def note_destructor_nontype_here : Note<
> +  "non-type declaration found by destructor name lookup">;
> +def ext_dtor_named_in_wrong_scope : Extension<
> +  "ISO C++ requires the name after '::~' to be found in the same scope as
> "
> +  "the name before '::~'">, InGroup;
> +def ext_dtor_name_missing_template_arguments : Extension<
> +  "ISO C++ requires template argument 

Re: [clang] 0e3a487 - PR12350: Handle remaining cases permitted by CWG DR 244.

2020-02-10 Thread Nico Weber via cfe-commits
On Sun, Feb 9, 2020 at 2:34 PM Richard Smith  wrote:

> On Sun, 9 Feb 2020, 01:09 Nico Weber via cfe-commits, <
> cfe-commits@lists.llvm.org> wrote:
>
>> Our code fails to build with "destructor cannot be declared using a type
>> alias" after this, without us changing language mode or anything.
>>
>> Is that intended?
>>
>
> Can you provide a sketch of what you were doing? There are certainly cases
> where I'd expect that now --  where you find a typedef through in "bad"
> (extension) place and find a non-typedef elsewhere.
>

namespace perfetto {
class ConsumerEndpoint { . // 1
 public:
  virtual ~ConsumerEndpoint();
};
class TracingService {
 public:
  using ProducerEndpoint = perfetto::ProducerEndpoint;
  using ConsumerEndpoint = perfetto::ConsumerEndpoint;
};
TracingService::ConsumerEndpoint::~ConsumerEndpoint() = default;
}

1:
https://cs.chromium.org/chromium/src/third_party/perfetto/include/perfetto/ext/tracing/core/tracing_service.h?sq=package:chromium=0=55

2:
https://cs.chromium.org/chromium/src/third_party/perfetto/include/perfetto/ext/tracing/core/tracing_service.h?q=using%5C+ConsumerEndpoint=package:chromium=0=234

3:
https://android-review.googlesource.com/c/platform/external/perfetto/+/1229901/1/src/tracing/core/virtual_destructors.cc
lhs

Upon closer look, that was the only instance we had.

Can this be a default-error-mapped warning so that projects have some
>> incremental transition path for this?
>>
>
> That seems reasonable, yes.
>
> On Fri, Feb 7, 2020 at 9:41 PM Richard Smith via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>>
>>> Author: Richard Smith
>>> Date: 2020-02-07T18:40:41-08:00
>>> New Revision: 0e3a48778408b505946e465abf5c77a2ddd4918c
>>>
>>> URL:
>>> https://github.com/llvm/llvm-project/commit/0e3a48778408b505946e465abf5c77a2ddd4918c
>>> DIFF:
>>> https://github.com/llvm/llvm-project/commit/0e3a48778408b505946e465abf5c77a2ddd4918c.diff
>>>
>>> LOG: PR12350: Handle remaining cases permitted by CWG DR 244.
>>>
>>> Also add extension warnings for the cases that are disallowed by the
>>> current rules for destructor name lookup, refactor and simplify the
>>> lookup code, and improve the diagnostic quality when lookup fails.
>>>
>>> The special case we previously supported for converting
>>> p->N::S::~S() from naming a class template into naming a
>>> specialization thereof is subsumed by a more general rule here (which is
>>> also consistent with Clang's historical behavior and that of other
>>> compilers): if we can't find a suitable S in N, also look in N::S.
>>>
>>> The extension warnings are off by default, except for a warning when
>>> lookup for p->N::S::~T() looks for T in scope instead of in N (or N::S).
>>> That seems sufficiently heinous to warn on by default, especially since
>>> we can't support it for a dependent nested-name-specifier.
>>>
>>> Added:
>>>
>>>
>>> Modified:
>>> clang/include/clang/Basic/DiagnosticGroups.td
>>> clang/include/clang/Basic/DiagnosticSemaKinds.td
>>> clang/lib/AST/NestedNameSpecifier.cpp
>>> clang/lib/Sema/DeclSpec.cpp
>>> clang/lib/Sema/SemaExprCXX.cpp
>>> clang/test/CXX/class/class.mem/p13.cpp
>>> clang/test/CXX/drs/dr2xx.cpp
>>> clang/test/CXX/drs/dr3xx.cpp
>>> clang/test/FixIt/fixit.cpp
>>> clang/test/Parser/cxx-decl.cpp
>>> clang/test/SemaCXX/constructor.cpp
>>> clang/test/SemaCXX/destructor.cpp
>>> clang/test/SemaCXX/pseudo-destructors.cpp
>>>
>>> Removed:
>>>
>>>
>>>
>>>
>>> 
>>> diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td
>>> b/clang/include/clang/Basic/DiagnosticGroups.td
>>> index a2bc29986a07..8c54723cdbab 100644
>>> --- a/clang/include/clang/Basic/DiagnosticGroups.td
>>> +++ b/clang/include/clang/Basic/DiagnosticGroups.td
>>> @@ -192,6 +192,7 @@ def CXX2aDesignator : DiagGroup<"c++2a-designator">;
>>>  // designators (including the warning controlled by -Wc++2a-designator).
>>>  def C99Designator : DiagGroup<"c99-designator", [CXX2aDesignator]>;
>>>  def GNUDesignator : DiagGroup<"gnu-designator">;
>>> +def DtorName : DiagGroup<"dtor-name">;
>>>
>>>  def DynamicExceptionSpec
>>>  : DiagGroup<"dynamic-exception-spec",
>>> [DeprecatedDynamicExceptionSpec]>;
>>>
>>> diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td
>>> b/clang/include/clang/Basic/DiagnosticSemaKinds.td
>>> index 9de60d3a8d27..82861f0d5d72 100644
>>> --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
>>> +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
>>> @@ -1911,17 +1911,33 @@ def err_destructor_with_params :
>>> Error<"destructor cannot have any parameters">;
>>>  def err_destructor_variadic : Error<"destructor cannot be variadic">;
>>>  def err_destructor_typedef_name : Error<
>>>"destructor cannot be declared using a %select{typedef|type alias}1
>>> %0 of the class name">;
>>> +def err_undeclared_destructor_name : Error<
>>> +  "undeclared identifier %0 in destructor 

Re: [clang] 0e3a487 - PR12350: Handle remaining cases permitted by CWG DR 244.

2020-02-10 Thread Richard Smith via cfe-commits
On Sun, 9 Feb 2020 at 11:33, Richard Smith  wrote:

> On Sun, 9 Feb 2020, 01:09 Nico Weber via cfe-commits, <
> cfe-commits@lists.llvm.org> wrote:
>
>> Our code fails to build with "destructor cannot be declared using a type
>> alias" after this, without us changing language mode or anything.
>>
>> Is that intended?
>>
>
> Can you provide a sketch of what you were doing? There are certainly cases
> where I'd expect that now --  where you find a typedef through in "bad"
> (extension) place and find a non-typedef elsewhere.
>

I found that we were rejecting potentially-valid code in some cases:

struct X { ~X(); };
using X = X;
::X::~X() {} // rejected because we find the typedef-name not the class-name

Fixed in llvmorg-11-init-2613-g76f888d0a53.


> Can this be a default-error-mapped warning so that projects have some
>> incremental transition path for this?
>>
>
> That seems reasonable, yes.
>

Now accepted as an error-by-default extension (-Wno-dtor-typedef to disable
the error), in the same commit. (This doesn't have a fixit hint yet,
though.)


> On Fri, Feb 7, 2020 at 9:41 PM Richard Smith via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>>
>>> Author: Richard Smith
>>> Date: 2020-02-07T18:40:41-08:00
>>> New Revision: 0e3a48778408b505946e465abf5c77a2ddd4918c
>>>
>>> URL:
>>> https://github.com/llvm/llvm-project/commit/0e3a48778408b505946e465abf5c77a2ddd4918c
>>> DIFF:
>>> https://github.com/llvm/llvm-project/commit/0e3a48778408b505946e465abf5c77a2ddd4918c.diff
>>>
>>> LOG: PR12350: Handle remaining cases permitted by CWG DR 244.
>>>
>>> Also add extension warnings for the cases that are disallowed by the
>>> current rules for destructor name lookup, refactor and simplify the
>>> lookup code, and improve the diagnostic quality when lookup fails.
>>>
>>> The special case we previously supported for converting
>>> p->N::S::~S() from naming a class template into naming a
>>> specialization thereof is subsumed by a more general rule here (which is
>>> also consistent with Clang's historical behavior and that of other
>>> compilers): if we can't find a suitable S in N, also look in N::S.
>>>
>>> The extension warnings are off by default, except for a warning when
>>> lookup for p->N::S::~T() looks for T in scope instead of in N (or N::S).
>>> That seems sufficiently heinous to warn on by default, especially since
>>> we can't support it for a dependent nested-name-specifier.
>>>
>>> Added:
>>>
>>>
>>> Modified:
>>> clang/include/clang/Basic/DiagnosticGroups.td
>>> clang/include/clang/Basic/DiagnosticSemaKinds.td
>>> clang/lib/AST/NestedNameSpecifier.cpp
>>> clang/lib/Sema/DeclSpec.cpp
>>> clang/lib/Sema/SemaExprCXX.cpp
>>> clang/test/CXX/class/class.mem/p13.cpp
>>> clang/test/CXX/drs/dr2xx.cpp
>>> clang/test/CXX/drs/dr3xx.cpp
>>> clang/test/FixIt/fixit.cpp
>>> clang/test/Parser/cxx-decl.cpp
>>> clang/test/SemaCXX/constructor.cpp
>>> clang/test/SemaCXX/destructor.cpp
>>> clang/test/SemaCXX/pseudo-destructors.cpp
>>>
>>> Removed:
>>>
>>>
>>>
>>>
>>> 
>>> diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td
>>> b/clang/include/clang/Basic/DiagnosticGroups.td
>>> index a2bc29986a07..8c54723cdbab 100644
>>> --- a/clang/include/clang/Basic/DiagnosticGroups.td
>>> +++ b/clang/include/clang/Basic/DiagnosticGroups.td
>>> @@ -192,6 +192,7 @@ def CXX2aDesignator : DiagGroup<"c++2a-designator">;
>>>  // designators (including the warning controlled by -Wc++2a-designator).
>>>  def C99Designator : DiagGroup<"c99-designator", [CXX2aDesignator]>;
>>>  def GNUDesignator : DiagGroup<"gnu-designator">;
>>> +def DtorName : DiagGroup<"dtor-name">;
>>>
>>>  def DynamicExceptionSpec
>>>  : DiagGroup<"dynamic-exception-spec",
>>> [DeprecatedDynamicExceptionSpec]>;
>>>
>>> diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td
>>> b/clang/include/clang/Basic/DiagnosticSemaKinds.td
>>> index 9de60d3a8d27..82861f0d5d72 100644
>>> --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
>>> +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
>>> @@ -1911,17 +1911,33 @@ def err_destructor_with_params :
>>> Error<"destructor cannot have any parameters">;
>>>  def err_destructor_variadic : Error<"destructor cannot be variadic">;
>>>  def err_destructor_typedef_name : Error<
>>>"destructor cannot be declared using a %select{typedef|type alias}1
>>> %0 of the class name">;
>>> +def err_undeclared_destructor_name : Error<
>>> +  "undeclared identifier %0 in destructor name">;
>>>  def err_destructor_name : Error<
>>>"expected the class name after '~' to name the enclosing class">;
>>> -def err_destructor_class_name : Error<
>>> -  "expected the class name after '~' to name a destructor">;
>>> -def err_ident_in_dtor_not_a_type : Error<
>>> +def err_destructor_name_nontype : Error<
>>> +  "identifier %0 after '~' in destructor name does not name a type">;
>>> +def 

Re: [clang] 0e3a487 - PR12350: Handle remaining cases permitted by CWG DR 244.

2020-02-09 Thread Richard Smith via cfe-commits
On Sun, 9 Feb 2020, 01:09 Nico Weber via cfe-commits, <
cfe-commits@lists.llvm.org> wrote:

> Our code fails to build with "destructor cannot be declared using a type
> alias" after this, without us changing language mode or anything.
>
> Is that intended?
>

Can you provide a sketch of what you were doing? There are certainly cases
where I'd expect that now --  where you find a typedef through in "bad"
(extension) place and find a non-typedef elsewhere.

Can this be a default-error-mapped warning so that projects have some
> incremental transition path for this?
>

That seems reasonable, yes.

On Fri, Feb 7, 2020 at 9:41 PM Richard Smith via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>>
>> Author: Richard Smith
>> Date: 2020-02-07T18:40:41-08:00
>> New Revision: 0e3a48778408b505946e465abf5c77a2ddd4918c
>>
>> URL:
>> https://github.com/llvm/llvm-project/commit/0e3a48778408b505946e465abf5c77a2ddd4918c
>> DIFF:
>> https://github.com/llvm/llvm-project/commit/0e3a48778408b505946e465abf5c77a2ddd4918c.diff
>>
>> LOG: PR12350: Handle remaining cases permitted by CWG DR 244.
>>
>> Also add extension warnings for the cases that are disallowed by the
>> current rules for destructor name lookup, refactor and simplify the
>> lookup code, and improve the diagnostic quality when lookup fails.
>>
>> The special case we previously supported for converting
>> p->N::S::~S() from naming a class template into naming a
>> specialization thereof is subsumed by a more general rule here (which is
>> also consistent with Clang's historical behavior and that of other
>> compilers): if we can't find a suitable S in N, also look in N::S.
>>
>> The extension warnings are off by default, except for a warning when
>> lookup for p->N::S::~T() looks for T in scope instead of in N (or N::S).
>> That seems sufficiently heinous to warn on by default, especially since
>> we can't support it for a dependent nested-name-specifier.
>>
>> Added:
>>
>>
>> Modified:
>> clang/include/clang/Basic/DiagnosticGroups.td
>> clang/include/clang/Basic/DiagnosticSemaKinds.td
>> clang/lib/AST/NestedNameSpecifier.cpp
>> clang/lib/Sema/DeclSpec.cpp
>> clang/lib/Sema/SemaExprCXX.cpp
>> clang/test/CXX/class/class.mem/p13.cpp
>> clang/test/CXX/drs/dr2xx.cpp
>> clang/test/CXX/drs/dr3xx.cpp
>> clang/test/FixIt/fixit.cpp
>> clang/test/Parser/cxx-decl.cpp
>> clang/test/SemaCXX/constructor.cpp
>> clang/test/SemaCXX/destructor.cpp
>> clang/test/SemaCXX/pseudo-destructors.cpp
>>
>> Removed:
>>
>>
>>
>>
>> 
>> diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td
>> b/clang/include/clang/Basic/DiagnosticGroups.td
>> index a2bc29986a07..8c54723cdbab 100644
>> --- a/clang/include/clang/Basic/DiagnosticGroups.td
>> +++ b/clang/include/clang/Basic/DiagnosticGroups.td
>> @@ -192,6 +192,7 @@ def CXX2aDesignator : DiagGroup<"c++2a-designator">;
>>  // designators (including the warning controlled by -Wc++2a-designator).
>>  def C99Designator : DiagGroup<"c99-designator", [CXX2aDesignator]>;
>>  def GNUDesignator : DiagGroup<"gnu-designator">;
>> +def DtorName : DiagGroup<"dtor-name">;
>>
>>  def DynamicExceptionSpec
>>  : DiagGroup<"dynamic-exception-spec",
>> [DeprecatedDynamicExceptionSpec]>;
>>
>> diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td
>> b/clang/include/clang/Basic/DiagnosticSemaKinds.td
>> index 9de60d3a8d27..82861f0d5d72 100644
>> --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
>> +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
>> @@ -1911,17 +1911,33 @@ def err_destructor_with_params :
>> Error<"destructor cannot have any parameters">;
>>  def err_destructor_variadic : Error<"destructor cannot be variadic">;
>>  def err_destructor_typedef_name : Error<
>>"destructor cannot be declared using a %select{typedef|type alias}1 %0
>> of the class name">;
>> +def err_undeclared_destructor_name : Error<
>> +  "undeclared identifier %0 in destructor name">;
>>  def err_destructor_name : Error<
>>"expected the class name after '~' to name the enclosing class">;
>> -def err_destructor_class_name : Error<
>> -  "expected the class name after '~' to name a destructor">;
>> -def err_ident_in_dtor_not_a_type : Error<
>> +def err_destructor_name_nontype : Error<
>> +  "identifier %0 after '~' in destructor name does not name a type">;
>> +def err_destructor_expr_mismatch : Error<
>> +  "identifier %0 in object destruction expression does not name the type
>> "
>> +  "%1 of the object being destroyed">;
>> +def err_destructor_expr_nontype : Error<
>>"identifier %0 in object destruction expression does not name a type">;
>>  def err_destructor_expr_type_mismatch : Error<
>>"destructor type %0 in object destruction expression does not match
>> the "
>>"type %1 of the object being destroyed">;
>>  def note_destructor_type_here : Note<
>> -  "type %0 is declared here">;
>> +  "type %0 

Re: [clang] 0e3a487 - PR12350: Handle remaining cases permitted by CWG DR 244.

2020-02-08 Thread Nico Weber via cfe-commits
(Also, it'd be nice if the "destructor cannot be declared using a type
alias" diag had a fixit attached to it :) )

On Sat, Feb 8, 2020 at 7:09 PM Nico Weber  wrote:

> Our code fails to build with "destructor cannot be declared using a type
> alias" after this, without us changing language mode or anything.
>
> Is that intended? Can this be a default-error-mapped warning so that
> projects have some incremental transition path for this?
>
> On Fri, Feb 7, 2020 at 9:41 PM Richard Smith via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>>
>> Author: Richard Smith
>> Date: 2020-02-07T18:40:41-08:00
>> New Revision: 0e3a48778408b505946e465abf5c77a2ddd4918c
>>
>> URL:
>> https://github.com/llvm/llvm-project/commit/0e3a48778408b505946e465abf5c77a2ddd4918c
>> DIFF:
>> https://github.com/llvm/llvm-project/commit/0e3a48778408b505946e465abf5c77a2ddd4918c.diff
>>
>> LOG: PR12350: Handle remaining cases permitted by CWG DR 244.
>>
>> Also add extension warnings for the cases that are disallowed by the
>> current rules for destructor name lookup, refactor and simplify the
>> lookup code, and improve the diagnostic quality when lookup fails.
>>
>> The special case we previously supported for converting
>> p->N::S::~S() from naming a class template into naming a
>> specialization thereof is subsumed by a more general rule here (which is
>> also consistent with Clang's historical behavior and that of other
>> compilers): if we can't find a suitable S in N, also look in N::S.
>>
>> The extension warnings are off by default, except for a warning when
>> lookup for p->N::S::~T() looks for T in scope instead of in N (or N::S).
>> That seems sufficiently heinous to warn on by default, especially since
>> we can't support it for a dependent nested-name-specifier.
>>
>> Added:
>>
>>
>> Modified:
>> clang/include/clang/Basic/DiagnosticGroups.td
>> clang/include/clang/Basic/DiagnosticSemaKinds.td
>> clang/lib/AST/NestedNameSpecifier.cpp
>> clang/lib/Sema/DeclSpec.cpp
>> clang/lib/Sema/SemaExprCXX.cpp
>> clang/test/CXX/class/class.mem/p13.cpp
>> clang/test/CXX/drs/dr2xx.cpp
>> clang/test/CXX/drs/dr3xx.cpp
>> clang/test/FixIt/fixit.cpp
>> clang/test/Parser/cxx-decl.cpp
>> clang/test/SemaCXX/constructor.cpp
>> clang/test/SemaCXX/destructor.cpp
>> clang/test/SemaCXX/pseudo-destructors.cpp
>>
>> Removed:
>>
>>
>>
>>
>> 
>> diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td
>> b/clang/include/clang/Basic/DiagnosticGroups.td
>> index a2bc29986a07..8c54723cdbab 100644
>> --- a/clang/include/clang/Basic/DiagnosticGroups.td
>> +++ b/clang/include/clang/Basic/DiagnosticGroups.td
>> @@ -192,6 +192,7 @@ def CXX2aDesignator : DiagGroup<"c++2a-designator">;
>>  // designators (including the warning controlled by -Wc++2a-designator).
>>  def C99Designator : DiagGroup<"c99-designator", [CXX2aDesignator]>;
>>  def GNUDesignator : DiagGroup<"gnu-designator">;
>> +def DtorName : DiagGroup<"dtor-name">;
>>
>>  def DynamicExceptionSpec
>>  : DiagGroup<"dynamic-exception-spec",
>> [DeprecatedDynamicExceptionSpec]>;
>>
>> diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td
>> b/clang/include/clang/Basic/DiagnosticSemaKinds.td
>> index 9de60d3a8d27..82861f0d5d72 100644
>> --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
>> +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
>> @@ -1911,17 +1911,33 @@ def err_destructor_with_params :
>> Error<"destructor cannot have any parameters">;
>>  def err_destructor_variadic : Error<"destructor cannot be variadic">;
>>  def err_destructor_typedef_name : Error<
>>"destructor cannot be declared using a %select{typedef|type alias}1 %0
>> of the class name">;
>> +def err_undeclared_destructor_name : Error<
>> +  "undeclared identifier %0 in destructor name">;
>>  def err_destructor_name : Error<
>>"expected the class name after '~' to name the enclosing class">;
>> -def err_destructor_class_name : Error<
>> -  "expected the class name after '~' to name a destructor">;
>> -def err_ident_in_dtor_not_a_type : Error<
>> +def err_destructor_name_nontype : Error<
>> +  "identifier %0 after '~' in destructor name does not name a type">;
>> +def err_destructor_expr_mismatch : Error<
>> +  "identifier %0 in object destruction expression does not name the type
>> "
>> +  "%1 of the object being destroyed">;
>> +def err_destructor_expr_nontype : Error<
>>"identifier %0 in object destruction expression does not name a type">;
>>  def err_destructor_expr_type_mismatch : Error<
>>"destructor type %0 in object destruction expression does not match
>> the "
>>"type %1 of the object being destroyed">;
>>  def note_destructor_type_here : Note<
>> -  "type %0 is declared here">;
>> +  "type %0 found by destructor name lookup">;
>> +def note_destructor_nontype_here : Note<
>> +  "non-type declaration found by destructor name lookup">;
>> +def 

Re: [clang] 0e3a487 - PR12350: Handle remaining cases permitted by CWG DR 244.

2020-02-08 Thread Nico Weber via cfe-commits
Our code fails to build with "destructor cannot be declared using a type
alias" after this, without us changing language mode or anything.

Is that intended? Can this be a default-error-mapped warning so that
projects have some incremental transition path for this?

On Fri, Feb 7, 2020 at 9:41 PM Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

>
> Author: Richard Smith
> Date: 2020-02-07T18:40:41-08:00
> New Revision: 0e3a48778408b505946e465abf5c77a2ddd4918c
>
> URL:
> https://github.com/llvm/llvm-project/commit/0e3a48778408b505946e465abf5c77a2ddd4918c
> DIFF:
> https://github.com/llvm/llvm-project/commit/0e3a48778408b505946e465abf5c77a2ddd4918c.diff
>
> LOG: PR12350: Handle remaining cases permitted by CWG DR 244.
>
> Also add extension warnings for the cases that are disallowed by the
> current rules for destructor name lookup, refactor and simplify the
> lookup code, and improve the diagnostic quality when lookup fails.
>
> The special case we previously supported for converting
> p->N::S::~S() from naming a class template into naming a
> specialization thereof is subsumed by a more general rule here (which is
> also consistent with Clang's historical behavior and that of other
> compilers): if we can't find a suitable S in N, also look in N::S.
>
> The extension warnings are off by default, except for a warning when
> lookup for p->N::S::~T() looks for T in scope instead of in N (or N::S).
> That seems sufficiently heinous to warn on by default, especially since
> we can't support it for a dependent nested-name-specifier.
>
> Added:
>
>
> Modified:
> clang/include/clang/Basic/DiagnosticGroups.td
> clang/include/clang/Basic/DiagnosticSemaKinds.td
> clang/lib/AST/NestedNameSpecifier.cpp
> clang/lib/Sema/DeclSpec.cpp
> clang/lib/Sema/SemaExprCXX.cpp
> clang/test/CXX/class/class.mem/p13.cpp
> clang/test/CXX/drs/dr2xx.cpp
> clang/test/CXX/drs/dr3xx.cpp
> clang/test/FixIt/fixit.cpp
> clang/test/Parser/cxx-decl.cpp
> clang/test/SemaCXX/constructor.cpp
> clang/test/SemaCXX/destructor.cpp
> clang/test/SemaCXX/pseudo-destructors.cpp
>
> Removed:
>
>
>
>
> 
> diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td
> b/clang/include/clang/Basic/DiagnosticGroups.td
> index a2bc29986a07..8c54723cdbab 100644
> --- a/clang/include/clang/Basic/DiagnosticGroups.td
> +++ b/clang/include/clang/Basic/DiagnosticGroups.td
> @@ -192,6 +192,7 @@ def CXX2aDesignator : DiagGroup<"c++2a-designator">;
>  // designators (including the warning controlled by -Wc++2a-designator).
>  def C99Designator : DiagGroup<"c99-designator", [CXX2aDesignator]>;
>  def GNUDesignator : DiagGroup<"gnu-designator">;
> +def DtorName : DiagGroup<"dtor-name">;
>
>  def DynamicExceptionSpec
>  : DiagGroup<"dynamic-exception-spec",
> [DeprecatedDynamicExceptionSpec]>;
>
> diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td
> b/clang/include/clang/Basic/DiagnosticSemaKinds.td
> index 9de60d3a8d27..82861f0d5d72 100644
> --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
> +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
> @@ -1911,17 +1911,33 @@ def err_destructor_with_params : Error<"destructor
> cannot have any parameters">;
>  def err_destructor_variadic : Error<"destructor cannot be variadic">;
>  def err_destructor_typedef_name : Error<
>"destructor cannot be declared using a %select{typedef|type alias}1 %0
> of the class name">;
> +def err_undeclared_destructor_name : Error<
> +  "undeclared identifier %0 in destructor name">;
>  def err_destructor_name : Error<
>"expected the class name after '~' to name the enclosing class">;
> -def err_destructor_class_name : Error<
> -  "expected the class name after '~' to name a destructor">;
> -def err_ident_in_dtor_not_a_type : Error<
> +def err_destructor_name_nontype : Error<
> +  "identifier %0 after '~' in destructor name does not name a type">;
> +def err_destructor_expr_mismatch : Error<
> +  "identifier %0 in object destruction expression does not name the type "
> +  "%1 of the object being destroyed">;
> +def err_destructor_expr_nontype : Error<
>"identifier %0 in object destruction expression does not name a type">;
>  def err_destructor_expr_type_mismatch : Error<
>"destructor type %0 in object destruction expression does not match the
> "
>"type %1 of the object being destroyed">;
>  def note_destructor_type_here : Note<
> -  "type %0 is declared here">;
> +  "type %0 found by destructor name lookup">;
> +def note_destructor_nontype_here : Note<
> +  "non-type declaration found by destructor name lookup">;
> +def ext_dtor_named_in_wrong_scope : Extension<
> +  "ISO C++ requires the name after '::~' to be found in the same scope as
> "
> +  "the name before '::~'">, InGroup;
> +def ext_dtor_name_missing_template_arguments : Extension<
> +  "ISO C++ requires template argument list in destructor name">,

[clang] 0e3a487 - PR12350: Handle remaining cases permitted by CWG DR 244.

2020-02-07 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-02-07T18:40:41-08:00
New Revision: 0e3a48778408b505946e465abf5c77a2ddd4918c

URL: 
https://github.com/llvm/llvm-project/commit/0e3a48778408b505946e465abf5c77a2ddd4918c
DIFF: 
https://github.com/llvm/llvm-project/commit/0e3a48778408b505946e465abf5c77a2ddd4918c.diff

LOG: PR12350: Handle remaining cases permitted by CWG DR 244.

Also add extension warnings for the cases that are disallowed by the
current rules for destructor name lookup, refactor and simplify the
lookup code, and improve the diagnostic quality when lookup fails.

The special case we previously supported for converting
p->N::S::~S() from naming a class template into naming a
specialization thereof is subsumed by a more general rule here (which is
also consistent with Clang's historical behavior and that of other
compilers): if we can't find a suitable S in N, also look in N::S.

The extension warnings are off by default, except for a warning when
lookup for p->N::S::~T() looks for T in scope instead of in N (or N::S).
That seems sufficiently heinous to warn on by default, especially since
we can't support it for a dependent nested-name-specifier.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/NestedNameSpecifier.cpp
clang/lib/Sema/DeclSpec.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/CXX/class/class.mem/p13.cpp
clang/test/CXX/drs/dr2xx.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/FixIt/fixit.cpp
clang/test/Parser/cxx-decl.cpp
clang/test/SemaCXX/constructor.cpp
clang/test/SemaCXX/destructor.cpp
clang/test/SemaCXX/pseudo-destructors.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index a2bc29986a07..8c54723cdbab 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -192,6 +192,7 @@ def CXX2aDesignator : DiagGroup<"c++2a-designator">;
 // designators (including the warning controlled by -Wc++2a-designator).
 def C99Designator : DiagGroup<"c99-designator", [CXX2aDesignator]>;
 def GNUDesignator : DiagGroup<"gnu-designator">;
+def DtorName : DiagGroup<"dtor-name">;
 
 def DynamicExceptionSpec
 : DiagGroup<"dynamic-exception-spec", [DeprecatedDynamicExceptionSpec]>;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 9de60d3a8d27..82861f0d5d72 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1911,17 +1911,33 @@ def err_destructor_with_params : Error<"destructor 
cannot have any parameters">;
 def err_destructor_variadic : Error<"destructor cannot be variadic">;
 def err_destructor_typedef_name : Error<
   "destructor cannot be declared using a %select{typedef|type alias}1 %0 of 
the class name">;
+def err_undeclared_destructor_name : Error<
+  "undeclared identifier %0 in destructor name">;
 def err_destructor_name : Error<
   "expected the class name after '~' to name the enclosing class">;
-def err_destructor_class_name : Error<
-  "expected the class name after '~' to name a destructor">;
-def err_ident_in_dtor_not_a_type : Error<
+def err_destructor_name_nontype : Error<
+  "identifier %0 after '~' in destructor name does not name a type">;
+def err_destructor_expr_mismatch : Error<
+  "identifier %0 in object destruction expression does not name the type "
+  "%1 of the object being destroyed">;
+def err_destructor_expr_nontype : Error<
   "identifier %0 in object destruction expression does not name a type">;
 def err_destructor_expr_type_mismatch : Error<
   "destructor type %0 in object destruction expression does not match the "
   "type %1 of the object being destroyed">;
 def note_destructor_type_here : Note<
-  "type %0 is declared here">;
+  "type %0 found by destructor name lookup">;
+def note_destructor_nontype_here : Note<
+  "non-type declaration found by destructor name lookup">;
+def ext_dtor_named_in_wrong_scope : Extension<
+  "ISO C++ requires the name after '::~' to be found in the same scope as "
+  "the name before '::~'">, InGroup;
+def ext_dtor_name_missing_template_arguments : Extension<
+  "ISO C++ requires template argument list in destructor name">,
+  InGroup;
+def ext_qualified_dtor_named_in_lexical_scope : ExtWarn<
+  "qualified destructor name only found in lexical scope; omit the qualifier "
+  "to find this type name by unqualified lookup">, InGroup;
 
 def err_destroy_attr_on_non_static_var : Error<
   "%select{no_destroy|always_destroy}0 attribute can only be applied to a"

diff  --git a/clang/lib/AST/NestedNameSpecifier.cpp 
b/clang/lib/AST/NestedNameSpecifier.cpp
index 137953fa8203..81130512bfe1 100644
--- a/clang/lib/AST/NestedNameSpecifier.cpp
+++