r220363 - Disable the uninitialized field warning in uninstantiated classes.

Saleem Abdulrasool compnerd at compnerd.org
Tue Oct 21 20:48:25 PDT 2014


On Tue, Oct 21, 2014 at 7:52 PM, Richard Trieu <rtrieu at google.com> wrote:

> Author: rtrieu
> Date: Tue Oct 21 21:52:00 2014
> New Revision: 220363
>
> URL: http://llvm.org/viewvc/llvm-project?rev=220363&view=rev
> Log:
> Disable the uninitialized field warning in uninstantiated classes.
>
> If a templated class is not instantiated, then the AST for it could be
> missing
> some things that would throw the field checker off.  Wait until
> specialization
> before emitting these warnings.
>
> Modified:
>     cfe/trunk/lib/Sema/SemaDeclCXX.cpp
>     cfe/trunk/test/SemaCXX/uninitialized.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=220363&r1=220362&r2=220363&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Oct 21 21:52:00 2014
> @@ -2525,6 +2525,9 @@ namespace {
>
>      const CXXRecordDecl *RD = Constructor->getParent();
>
> +    if (RD->getDescribedClassTemplate() != nullptr)
> +      return;
> +
>

Isn't the LLVM style to not explicitly check for nullptr?

That is:

  if (!RD->getDescribedClassTemplate())
    return;


>      // Holds fields that are uninitialized.
>      llvm::SmallPtrSet<ValueDecl*, 4> UninitializedFields;
>
>
> Modified: cfe/trunk/test/SemaCXX/uninitialized.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/uninitialized.cpp?rev=220363&r1=220362&r2=220363&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/uninitialized.cpp (original)
> +++ cfe/trunk/test/SemaCXX/uninitialized.cpp Tue Oct 21 21:52:00 2014
> @@ -1220,3 +1220,46 @@ namespace init_list {
>      {}
>    };
>  }
> +
> +namespace template_class {
> +class Foo {
> + public:
> +    int *Create() { return nullptr; }
> +};
> +
> +template <typename T>
> +class A {
> +public:
> +  // Don't warn on foo here.
> +  A() : ptr(foo->Create()) {}
> +
> +private:
> +  Foo *foo = new Foo;
> +  int *ptr;
> +};
> +
> +template <typename T>
> +class B {
> +public:
> +  // foo is uninitialized here, but class B is never instantiated.
> +  B() : ptr(foo->Create()) {}
> +
> +private:
> +  Foo *foo;
> +  int *ptr;
> +};
> +
> +template <typename T>
> +class C {
> +public:
> +  C() : ptr(foo->Create()) {}
> +  // expected-warning at -1 {{field 'foo' is uninitialized when used here}}
> +private:
> +  Foo *foo;
> +  int *ptr;
> +};
> +
> +C<int> c;
> +// expected-note at -1 {{in instantiation of member function
> 'template_class::C<int>::C' requested here}}
> +
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>



-- 
Saleem Abdulrasool
compnerd (at) compnerd (dot) org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141021/3b929cba/attachment.html>


More information about the cfe-commits mailing list