public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101376] New: Missing Wsuggest-attribute=const/Wsuggest-attribute=pure for throwing functions, wrong Wattributes for pure/const throwing functions
@ 2021-07-08  9:16 harald at gigawatt dot nl
  2021-07-08 10:46 ` [Bug c++/101376] " rguenth at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: harald at gigawatt dot nl @ 2021-07-08  9:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101376

            Bug ID: 101376
           Summary: Missing
                    Wsuggest-attribute=const/Wsuggest-attribute=pure for
                    throwing functions, wrong Wattributes for pure/const
                    throwing functions
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: harald at gigawatt dot nl
  Target Milestone: ---

According to PR100409, const/pure functions are allowed to throw. As such, I
would expect that

  void f() {
    throw "!";
  }

produces a diagnostic with -Wsuggest-attribute=const but no diagnostic is
produced.

In fact, if I modify this to add the attribute myself, like so:

  __attribute__((const)) void f() {
    throw "!";
  }

I get "warning: 'const' attribute on function returning 'void'". This warning
is documented but now wrong. The documentation reads

  "Because a const function cannot have any observable side effects it does not
make sense for it to return void. Declaring such a function is diagnosed."

A helper function to throw an exception makes sense to declare as returning
void, and meets the criteria of a const function.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/101376] Missing Wsuggest-attribute=const/Wsuggest-attribute=pure for throwing functions, wrong Wattributes for pure/const throwing functions
  2021-07-08  9:16 [Bug c++/101376] New: Missing Wsuggest-attribute=const/Wsuggest-attribute=pure for throwing functions, wrong Wattributes for pure/const throwing functions harald at gigawatt dot nl
@ 2021-07-08 10:46 ` rguenth at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-07-08 10:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101376

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |diagnostic
   Last reconfirmed|                            |2021-07-08
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  Now, having EH as the only effect of a const function is of course
quite some obfuscation ;)

The first part is likely difficult since 'throw' appears as call to
__cxa_throw () to the IPA pure/const pass plus there's a
__cxa_allocate_exception call.  So our present implementation of EH makes
the function not actually 'const' - still a user can declare it 'const'.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-08 10:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-08  9:16 [Bug c++/101376] New: Missing Wsuggest-attribute=const/Wsuggest-attribute=pure for throwing functions, wrong Wattributes for pure/const throwing functions harald at gigawatt dot nl
2021-07-08 10:46 ` [Bug c++/101376] " rguenth at gcc dot gnu.org

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).