https://bugs.llvm.org/show_bug.cgi?id=50641

            Bug ID: 50641
           Summary: Valid combination of "constexpr", "[[unlikely]]" and
                    switch statement leads to "error: no return statement
                    in constexpr function"
           Product: clang
           Version: 12.0
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++2a
          Assignee: unassignedclangb...@nondot.org
          Reporter: t...@think-cell.com
                CC: blitzrak...@gmail.com, erik.pilking...@gmail.com,
                    llvm-bugs@lists.llvm.org, richard-l...@metafoo.co.uk

The following code fails to compile in clang++ 12
https://godbolt.org/z/eGM93Tqcr

constexpr 
char Test(int n) {
    switch( n )
    [[unlikely]] default: {
        case 0: return 'a';
        case 1: return 'b';
    }
}

with the message:
<source>:3:6: error: no return statement in constexpr function


Even if it seems odd at first sight, this is valid C++ and compiles on latest
 gcc https://godbolt.org/z/8YGfM3dM8
 and MSVC https://godbolt.org/z/MP7YaP5qv 
It is actually part of our production codebase, used there to implement a
"switch_no_default"-macro that asserts if a value occurs that's not among the
"cases".

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to