[cfe-commits] r166625 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaCXX/warn-unused-variables.cpp

Matthieu Monrocq matthieu.monrocq at gmail.com
Thu Oct 25 10:05:57 PDT 2012


On Wed, Oct 24, 2012 at 11:29 PM, David Blaikie <dblaikie at gmail.com> wrote:

> Author: dblaikie
> Date: Wed Oct 24 16:29:06 2012
> New Revision: 166625
>
> URL: http://llvm.org/viewvc/llvm-project?rev=166625&view=rev
> Log:
> Fix false positive in -Wunused-variable when a ctor call make involve
> cleanups.
>
> Modified:
>     cfe/trunk/lib/Sema/SemaDecl.cpp
>     cfe/trunk/test/SemaCXX/warn-unused-variables.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=166625&r1=166624&r2=166625&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Oct 24 16:29:06 2012
> @@ -1286,6 +1286,8 @@
>            return false;
>
>          if (const Expr *Init = VD->getInit()) {
> +          if (const ExprWithCleanups *Cleanups =
> dyn_cast<ExprWithCleanups>(Init))
> +            Init = Cleanups->getSubExpr();
>            const CXXConstructExpr *Construct =
>              dyn_cast<CXXConstructExpr>(Init);
>            if (Construct && !Construct->isElidable()) {
>
> Modified: cfe/trunk/test/SemaCXX/warn-unused-variables.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-variables.cpp?rev=166625&r1=166624&r2=166625&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/warn-unused-variables.cpp (original)
> +++ cfe/trunk/test/SemaCXX/warn-unused-variables.cpp Wed Oct 24 16:29:06
> 2012
> @@ -123,3 +123,15 @@
>      S3 z = a; // expected-warning {{unused variable 'z'}}
>    }
>  }
> +
> +namespace ctor_with_cleanups {
> +  struct S1 {
> +    ~S1();
> +  };
> +  struct S2 {
> +    S2(const S1&);
> +  };
> +  void func() {
> +    S2 s((S1()));
> +  }
> +}
>
>
So, here S1() will generate a cleanup... however "s" is still unused and of
little interest because if I were to write "S1();" there would be cleanup
and no "s", isn't it ?

I don't see the point in introducing a named variable when the effect of
not introducing it would be identical.

-- Matthieu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121025/ad27c886/attachment.html>


More information about the cfe-commits mailing list