This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/50734] const and pure attributes don't have the effect as in C
- From: "joseph at codesourcery dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 15 Oct 2011 15:47:27 +0000
- Subject: [Bug c++/50734] const and pure attributes don't have the effect as in C
- Auto-submitted: auto-generated
- References: <bug-50734-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50734
--- Comment #2 from joseph at codesourcery dot com <joseph at codesourcery dot com> 2011-10-15 15:47:27 UTC ---
On Sat, 15 Oct 2011, rguenth at gcc dot gnu.org wrote:
> This is because f can throw, you need to mark it nothrow as well in C++.
> Whether something throws or accesses global memory is orthogonal.
> Works with -fno-exceptions.
I don't see the difference here from C. In C, f might exit the program or
call longjmp (if you allow such functions to throw, I'd have thought they
could also not-return in other ways) - but if it does, the exit status, or
where it longjmps do, will only depend on the global state visible to f,
meaning that it will do so on the first time through the loop. The same
reasoning that it's safe to hoist the call out of the loop in C - the loop
is guaranteed to call f at least once with the same state as if it is
called before the loop - should apply in C++; throwing from a hoisted call
could not be distinguished by a catcher from throwing from the first call
in the loop.