[LLVMbugs] [Bug 10101] New: [QoI] error recovery and fixit for stray ; in function definition

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jun 8 10:31:41 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=10101

           Summary: [QoI] error recovery and fixit for stray ; in function
                    definition
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: richard-llvm at metafoo.co.uk
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


I occasionally forget to remove the semicolon after the function declaration
when copying it to write a function definition:


struct C
{
  int foo();
};

int C::foo();
{
}

C c;
int n = c.foo();


clang complains:

my_file.cpp:6:8: error: out-of-line declaration of a member must be a
definition
int C::foo();
    ~~~^
my_file.cpp:7:1: error: expected unqualified-id
{
^
my_file.cpp:11:9: error: use of undeclared identifier 'c'
int n = c.foo();
        ^


These errors are not awesome! A function declaration (which is the sole
declarator in the declaration) at namespace scope, followed by '{' or 'try' or
':', is most likely a function definition with a stray ';'. This would be
fantastic:

my_file.cpp:5:13: error: stray ';' in function definition
int C::foo();
            ^

(with a fixit to remove the ';').


The same error recovery should probably also apply to tag declarations at
namespace scope followed by '{' or ':', though those cases probably don't occur
in practice as frequently.


We're also skipping too far forwards when we encounter the stray '{': it seems
we skip to the next (top-level) semicolon and thus usually skip the rest of the
translation unit (as can be seen above: 'C c;' is skipped). This skipping is
also visible with typos like this:

extenr "C" {
  void f();
}

void g() {
  la la la la la;  
}

my_file.cpp:1:1: error: unknown type name 'extenr'; did you mean 'extern'?
extenr "C" {
^
my_file.cpp:1:8: error: expected unqualified-id
extenr "C" {
       ^

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list