[PATCH] Adding a diagnostic for member templates inside a local class

Gao, Yunzhong Yunzhong.Gao at am.sony.com
Wed Mar 13 23:51:17 PDT 2013


Hi Douglas,
Thank you for review.
I am attaching an updated patch with the following changes:

  1. The diagnostic is moved from lib/Parse to lib/SemaTemplate;
  2. Added a new test to test/SemaTemplate instead of test/Parser;
  3. In test/SemaTemplate/instantiate-exception-spec-cxx11.cpp, moved the class definition outside of the
      function body to avoid triggering the new diagnostic.
      I did experiment with adding an expected-error annotation there, but it seems that delaying the diagnostic
      from Parser to Sema triggers quite a few more error messages, e.g.,
          Line 52: use of undeclared identifier 'f'
          Line 54: no member named 'f' in 'S'
      I think adding more expected-error annotations would unnecessarily complicate the existing test. The
      proposed new test checks both function and class templates.

Could you review?
- Gao.

________________________________________
From: Douglas Gregor [dgregor at apple.com]
Sent: Wednesday, March 13, 2013 4:13 PM
To: Gao, Yunzhong
Cc: cfe-commits at cs.uiuc.edu
Subject: Re: [PATCH] Adding a diagnostic for member templates inside a local class

On Mar 13, 2013, at 12:55 PM, "Gao, Yunzhong" <Yunzhong.Gao at am.sony.com> wrote:

> Hi,
> Currently, clang++ accepts the following codes without any error message.
>
> int test(void)
> {
>  class A {
>    template<class T> class B
>    {  T t; };
>  };
>
>  return 0;
> }
>
> However, I believe that an error message is required according to the C++03 and C++11.
> In particular, section 14.5 clause 2 (of both specs) says "A local class shall not have member templates."
>
> The following patch adds a diagnostic for member templates declared inside a local class.

Generally, this looks good. However, I'd like to see it diagnosed in Sema, rather than in the parser, which we do for static data members and friends in local classes.

        - Doug








More information about the cfe-commits mailing list