[[nereturn]] атрибут на функции другаC++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 [[nereturn]] атрибут на функции друга

Сообщение Anonymous »

Я хочу объявить функцию друга в классе как [[[noreturn]] , но я не могу понять правильный синтаксис.
struct a
{
[[noreturn]] friend int b();
};

[[noreturn]] int b(){ throw 42; }
< /code>
Это не может компилироваться как на GCC, так и на Clang: < /p>
gcc message: < /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: < /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();
| ^


Подробнее здесь: https://stackoverflow.com/questions/794 ... -functions
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»