[LLVMbugs] [Bug 14304] New: -Winvalid-constexpr fails to warn on non-const array used in constexpr function

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Nov 9 12:26:57 PST 2012


http://llvm.org/bugs/show_bug.cgi?id=14304

             Bug #: 14304
           Summary: -Winvalid-constexpr fails to warn on non-const array
                    used in constexpr function
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: arthur.j.odwyer at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


cat >test.cc <<EOF
extern int global_array[1];

constexpr int true_positive(int i) {
    return global_array[0];
}

constexpr int false_negative(int i) {
    return global_array[i];
}
EOF
clang -std=c++11 -c test.cc

Clang gives the correct diagnostic ("constexpr function never produces a
constant expression") for "true_positive", but silently accepts
"false_negative".

The Standard says "the program is ill-formed; no diagnostic required"
(dcl.constexpr#5), but clearly Clang is making an effort to diagnose the issue
and is failing. So I'm calling this a bug, even though technically (per
dcl.constexpr#5) it's just a quality-of-implementation issue, i.e. an
enhancement request.

(Personally, I'd like to see Clang diagnose any constexpr function that is
*ever* uncomputable at compile time. I don't have a ton of experience with
constexpr yet, but I see huge disadvantages to permitting "non-const constexpr"
functions — and no correspondingly huge advantages — no matter what the
Standard says on the topic.)

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list