Bug 85374 - Confusing diagnostic for function with missing brace that looks like a function-try-block
Summary: Confusing diagnostic for function with missing brace that looks like a functi...
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2018-04-12 11:10 UTC by Jonathan Wakely
Modified: 2018-04-12 23:47 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2018-04-12 11:10:17 UTC
I had a function that originally looked like:

int func(int some, int params, int blah) {

and I removed the parameters, unintentionally also removing the opening brace at the end of the line, to give:

int func()
// Oops, opening brace missing
    try {
      throw 1;
    }
    catch (...) {
        return 0;
    }
    return 1;
}

a.cc:9:5: error: expected unqualified-id before 'return'
     return 1;
     ^~~~~~
a.cc:10:1: error: expected declaration before '}' token
 }
 ^

Clang does a bit better by saying "extraneous closing brace":

a.cc:9:5: error: expected unqualified-id
    return 1;
    ^
a.cc:10:1: error: extraneous closing brace ('}')
}
^
2 errors generated.


I couldn't figure out what was wrong with the code from GCC's error, and only saw the problem after trying to compile it with Clang.
Comment 1 Jonathan Wakely 2018-04-12 11:15:31 UTC
If we see a return statement outside a function block it should be a clue that there's some incorrect brace nesting going on.