[cfe-commits] [PATCH] Improve error recovery for comma/semicolon typo in declaration group

Richard Smith richard at metafoo.co.uk
Wed Oct 5 16:26:41 PDT 2011


Based on a true story...

Clang currently gives unhelpful diagnostics for cases such as this:

      static const char *const Triples[] = {
        "powerpc-linux-gnu",
        "powerpc-unknown-linux-gnu"
      },
      CandidateLibDirs.append(LibDirs, LibDirs + llvm::array_lengthof(LibDirs));

Viz:

lib/Driver/ToolChains.cpp:1582:7: error: default initialization of an object
of const type 'const char'
     CandidateLibDirs.append(LibDirs, LibDirs + llvm::array_lengthof(LibDirs));
     ^
lib/Driver/ToolChains.cpp:1582:23: error: expected ';' at end of declaration
     CandidateLibDirs.append(LibDirs, LibDirs + llvm::array_lengthof(LibDirs));
                     ^
                     ;

The attached patch is a conservative fix for this issue. In cases where a
declarator group contains a comma followed by a newline followed by something
which obviously is neither a declarator nor a typo for a declarator, we give a
fixit suggesting that a ; was intended:

lib/Driver/ToolChains.cpp:1581:8: error: expected ';' at end of declaration
      },
       ^ ;

OK to commit?

Thanks,
Richard
-------------- next part --------------
A non-text attachment was scrubbed...
Name: decl-comma-semi-typo.diff
Type: text/x-patch
Size: 6239 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20111006/e79e481d/attachment.bin>


More information about the cfe-commits mailing list