Я хочу объявить функцию друга в классе как [[[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
[[nereturn]] атрибут на функции друга ⇐ C++
Программы на C++. Форум разработчиков
1756445000
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();
| ^
Подробнее здесь: [url]https://stackoverflow.com/questions/79474680/noreturn-attribute-on-friend-functions[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия