public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "gcc at themudrest dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/62046] New: A catch in a class, without any try, compiles fine
Date: Thu, 07 Aug 2014 09:30:00 -0000 [thread overview]
Message-ID: <bug-62046-4@http.gcc.gnu.org/bugzilla/> (raw)
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
next reply other threads:[~2014-08-07 9:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-07 9:30 gcc at themudrest dot com [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bug-62046-4@http.gcc.gnu.org/bugzilla/ \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).