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

            Bug ID: 32904
           Summary: contexpr return type from a member function is allowed
                    where it should not
           Product: clang
           Version: 4.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++14
          Assignee: unassignedclangb...@nondot.org
          Reporter: mikhail.katl...@tuebingen.mpg.de
                CC: llvm-bugs@lists.llvm.org

Minimal example:

#include <iostream>

int f()
{
    static int n = 42;
    return n++;
}

struct A
{
    A()
    :   f_(&f)
    {

    }

    int constexpr n() const
    {
        return f_();
    }

    int (*f_)();
};

int main(int, char **)
{
    std::cout << A().n() << std::endl;
    std::cout << A().n() << std::endl;

    return 0;
}

Build with clang:
$ clang++ -std=c++14 example.cpp

Run:
$ ./a.out
42
43

Try building with gcc:
$ g++ -std=c++14 example.cpp
example.cpp:17:19: error: enclosing class of constexpr non-static member
function ‘int A::n() const’ is not a literal type
     int constexpr n() const
                   ^
example.cpp:9:8: note: ‘A’ is not literal because:
 struct A
        ^
example.cpp:9:8: note:   ‘A’ is not an aggregate, does not have a trivial
default constructor, and has no constexpr constructor that is not a copy or
move constructor

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

Reply via email to