public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/62046] New: A catch in a class, without any try, compiles fine
@ 2014-08-07 9:30 gcc at themudrest dot com
2014-08-07 9:36 ` [Bug c++/62046] " redi at gcc dot gnu.org
2014-09-19 10:57 ` paolo.carlini at oracle dot com
0 siblings, 2 replies; 3+ messages in thread
From: gcc at themudrest dot com @ 2014-08-07 9:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62046
Bug ID: 62046
Summary: A catch in a class, without any try, compiles fine
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: gcc at themudrest dot com
A catch can follow a method in a class, without any try. Isn't this a syntax
error? We couldn't find anything in the standard explaining it.
This is a vector for bugs in code, if your forget to include the try after a
method, the expected catch for throws in the method is not called.
Example code:
#include <iostream>
class TestTry
{
public:
// if you include the try after the method
// it is caught below, but if you forget it is not
void FunctionCatch() /*** No try here! ***/
{
std::cout << "FunctionCatch" << std::endl;
throw 42;
std::cout << "FunctionCatch post-throw" << std::endl;
}
// what is this catch doing here?
// shouldn't this be a compile error?
catch (...)
{
std::cout << "FunctionCatch caught!" << std::endl;
}
};
int main(int argc, char *argv[])
{
TestTry Object;
try
{
Object.FunctionCatch();
}
catch (...)
{
std::cout << "caught in main" << std::endl;
}
}
> g++ -Wall TestTry.cpp
> ./a.out
FunctionCatch
caught in main
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/62046] A catch in a class, without any try, compiles fine
2014-08-07 9:30 [Bug c++/62046] New: A catch in a class, without any try, compiles fine gcc at themudrest dot com
@ 2014-08-07 9:36 ` redi at gcc dot gnu.org
2014-09-19 10:57 ` paolo.carlini at oracle dot com
1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2014-08-07 9:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62046
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |accepts-invalid
Status|UNCONFIRMED |NEW
Last reconfirmed| |2014-08-07
Ever confirmed|0 |1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/62046] A catch in a class, without any try, compiles fine
2014-08-07 9:30 [Bug c++/62046] New: A catch in a class, without any try, compiles fine gcc at themudrest dot com
2014-08-07 9:36 ` [Bug c++/62046] " redi at gcc dot gnu.org
@ 2014-09-19 10:57 ` paolo.carlini at oracle dot com
1 sibling, 0 replies; 3+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-09-19 10:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62046
--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> ---
I think it can be reduced like this:
void foo() { } catch (...);
class bar { void foo() { } catch (...); };
we reject only the former.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-09-19 10:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-07 9:30 [Bug c++/62046] New: A catch in a class, without any try, compiles fine gcc at themudrest dot com
2014-08-07 9:36 ` [Bug c++/62046] " redi at gcc dot gnu.org
2014-09-19 10:57 ` paolo.carlini at oracle dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).