[[Noreturn]] Attribut über FreundenfunktionenC++

Programme in C++. Entwicklerforum
Anonymous
 [[Noreturn]] Attribut über Freundenfunktionen

Post by Anonymous »

Ich möchte eine Freundungsfunktion einer Klasse als [[Noreturn]] deklarieren, aber ich kann die richtige Syntax nicht ermitteln.

Code: Select all

struct a
{
[[noreturn]] friend int b();
};

[[noreturn]] int b(){ throw 42; }
< /code>
Dies kann sowohl auf GCC als auch auf Clang kompilieren: < /p>
GCC-Fehlermeldung: < /p>
warning: attribute ignored [-Wattributes]
X |     [[noreturn]] friend int b();
|                             ^
note: an attribute that appertains to a friend declaration that is not a definition is ignored
error: function 'int b()' declared '[[noreturn]]' but its first declaration was not
Y | [[noreturn]] int b(){ throw 42; }
|                  ^
:5:29: note: previous declaration of 'int b()'
X |     [[noreturn]] friend int b();
|                             ^
< /code>
Clang-Fehlermeldung: < /p>
error: an attribute list cannot appear here
X |     [[noreturn]] friend int b();
|     ^~~~~~~~~~~~
error: 'noreturn' attribute does not appear on the first declaration
Y | [[noreturn]] int b(){ throw 42; }
|   ^
note: previous declaration is here
X |     [[noreturn]] friend int b();
|                             ^

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post