[LLVMbugs] [Bug 15532] New: False positive for -Wunused-variable in function template when calling nontrivial ctor with __func__

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Mar 17 15:26:03 PDT 2013


            Bug ID: 15532
           Summary: False positive for -Wunused-variable in function
                    template when calling nontrivial ctor with __func__
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: matthewbg at google.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

class Parser {
  class Tracer {
    Tracer(const char*, Parser*);
  template <char delim> void ParseFoo() {
    Tracer trace(__func__, this);
  void ParseBar() {
    Tracer trace(__func__, this);

We warn on the 'trace' variable in ParseFoo, but not the one in ParseBar. The
Decl for 'trace' in ParseBar looks like:
VarDecl 0x3c83d70 </tmp/in.ii:10:5, col:32> trace 'class Parser::Tracer'
`-CXXConstructExpr 0x3c84268 <col:12, col:32> 'class Parser::Tracer' 'void
(const char *, class Parser *)'
  |-ImplicitCastExpr 0x3c84250 <col:18> 'const char *' <ArrayToPointerDecay>
  | `-PredefinedExpr 0x3c83e48 <col:18> 'const char [9]' lvalue __func__
  `-CXXThisExpr 0x3c83e60 <col:28> 'class Parser *' this
So, in ShouldDiagnoseUnusedDecl, we correctly determine that the constructor is
non-elidable and nontrivial, and return false.

On the other hand, the 'trace' in ParseFoo looks like this:
VarDecl 0x3c83c30 </tmp/in.ii:7:5, col:32> trace 'class Parser::Tracer'
`-ParenListExpr 0x3c83cf0 <col:17, col:32> 'NULL TYPE'
  |-PredefinedExpr 0x3c83c88 <col:18> '<dependent type>' lvalue __func__
  `-CXXThisExpr 0x3c83ca0 <col:28> 'class Parser *' this
We don't find a CXXConstructExpr, so ShouldDiagnoseUnusedDecl returns true.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130317/1707e004/attachment.html>

More information about the llvm-bugs mailing list