[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lmi] [PATCH] Use "noreturn" attribute in the function declaration t
Re: [lmi] [PATCH] Use "noreturn" attribute in the function declaration too
Wed, 15 Mar 2017 09:24:01 +0000
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0
On 2017-03-15 00:12, Vadim Zeitlin wrote:
> As previously mentioned, my reading of the Standard seems to indicate that
> not using the "noreturn" attribute in the function declaration, but using
> it in the function definition makes the program ill-formed. Whether I'm
> correct or not, it definitely makes it uncompilable with MSVC which gives
> many errors similar to the following one:
[split into several lines]
> any_member.hpp(572): error C2381: \
'__declspec(noreturn)' or '[[noreturn]]' differs (compiling source file
> The attached patch simply adds "[[noreturn]]" to the function declaration,
> which seems like the right fix to me. Could you please apply it?
Please try my commit 082dd93 instead and let me know whether it works
(once I push it; I want to consider your other, later patch first).
I agree that it was wrong to write [[noreturn]] on the definition but
not on the declaration. Your message cites 7.6.3/1 [dcl.attr.noreturn]:
| The attribute may be applied to the declarator-id in a function
| declaration. The first declaration of a function shall specify the
| noreturn attribute if any declaration of that function specifies the
| noreturn attribute.
and in this example the "first declaration" did not specify [[noreturn]].
However, your patch seems to suggest that, following a declaration that
specifies [[noreturn]], the definition of the same function may specify
it too. Reading between the lines of the standard, I think it's allowed
only on declarations. I.e., I think the word "may" in the first sentence
quoted above is exclusive: the standard doesn't grant permission for this
attribute to be used in any other situation than a function declaration.
This example seems to suggest that [[noreturn]] can be omitted from
| void fatal(void) [[noreturn]];
| void fatal(...)
and I'm reminded of experience with various msw compilers that allow
__declspec__ only on a declaration but forbid it on a definition that
is not a defining-declaration; that's my main reason for hesitating
to write it anywhere but on the first declaration.
cppreference.com seems to suggest something similar:
| This attribute applies to function declarations only.
But of course any function definition is a declaration, and that
article cites no authoritative source, so unfortunately we're
reduced to guesswork.