What does this C ++ 11 syntax mean?
[[ noreturn ]] void f () { throw "error"; }
The standard C ++ N3797 working draft states
The first declaration of the function indicates the noreturn attribute, if any declaration of this function points to the noreturn attribute. If a function is declared with an attribute noreturnin one translation unit and the same function is declared without noreturn in another translation unit, the program is poorly formed; no diagnostics required.
noreturn
What is meant by a function attribute?
, . "" : , .
, , , . ,
fork
/ .
,
main() { f(); g(); }
f() noreturn, g(), .
f()
g()
- ++ 11. , - , . , ( noreturn carries_dependency), .
carries_dependency
, noreturn : , , , undefined. ( ) , , noreturn. .
[[noreturn]] .
[[noreturn]]
#include <stdexcept> [[noreturn]] void report_error() { throw std::runtime_error("error"); } int f(int x) { if (x > 0) { return x; } report_error(); } int main() { f(1); }
[[noreturn]], f(): warning: control may reach end of non-void function.
warning: control may reach end of non-void function
GCC " noreturn , . , , , - . . , .
Source: https://habr.com/ru/post/1539130/More articles:How to build CFG based on a given regular expression - algorithmNSCollectionView resizes items like iTunes - cocoaСбой сборки. Не удалось найти тип "System.Globalization.SortVersion" - monoDocumenting a Python function with a docstring that is read in raw form and provides good sphinx output - pythonSetting Elasticsearch _score based on the field value in relation to another field value of the corresponding document - popularityHow is RDP for my cloud service? - virtual-machineConvert strings to double C ++ conversion - c ++Sorting a large file using Python heapq.merge - pythonError expanding TestCase abstract class from Laravel (error says that my extended class should be abstract) - phpMySQL - GROUP_CONCAT returns duplicate data, cannot use DISTINCT - sqlAll Articles