Skip to content

Overly pedantic [[noreturn]] restriction #131700

Open
@kimbarrett

Description

@kimbarrett

C++11 says that the first declaration of a function must specify the [[noreturn]] attribute if any declaration specifies it.

All of gcc, clang, and MSVC provide compiler-specific mechanisms to indicate a function is "noreturn". gcc and clang have attribute((noreturn)), while MSVC has __declspec(noreturn). gcc and MSVC treat their compiler-specific attributes as satisfying the first declaration attribute requirement, but clang does not. That is, this compiles cleanly with gcc, but clang issues a warning

attribute((noreturn)) void testfn(int);
[[noreturn]] void testfn(int);

and this compiles cleanly with MSVC, but clang issues a warning

__declspec(noreturn) void testfn(int);
[[noreturn]] void testfn(int);

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:frontendLanguage frontend issues, e.g. anything involving "Sema"diverges-from:msvcDoes the clang frontend diverge from msvc on this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions