[PATCH] templated static_assert

Aaron Ballman aaron at aaronballman.com
Mon Aug 4 13:37:57 PDT 2014


On Mon, Aug 4, 2014 at 2:52 PM, Richard Smith <richard at metafoo.co.uk> wrote:
> On Mon, Aug 4, 2014 at 11:48 AM, Richard Smith <richard at metafoo.co.uk>
> wrote:
>>
>> I don't think the diagnostic wording is right: 'template<typename T>' is
>> not "a template declaration" in itself. A better model for the diagnostic
>> might be this:
>>
>> <stdin>:1:34: error: a typedef cannot be a template
>> template<typename T> typedef int n;
>>                                  ^
>>
>> ... so "a static_assert declaration cannot be a template" (or "[...]
>> cannot be templated" or similar).
>>
>> Also, we should use the same diagnostic for the member-declaration and the
>> non-member-declaration cases. (Right now, the non-member case gives a
>> useless "C++ requires a type specifier" diagnostic.)
>
>
> Alternative approach: only check for tok::kw_static_assert in member
> declarations if we don't have TemplateInfo. Then, when we come to diagnose
> the unexpected static_assert keyword (maybe in ParseDeclarationSpecifiers or
> ParseImplicitInt), produce a custom diagnostic if we're within a template
> declaration.

Good suggestions -- I've committed in r214770. Thanks!

~Aaron



More information about the cfe-commits mailing list