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

            Bug ID: 22845
           Summary: [C++14] new expression should cause compilation error
                    if expression in a noptr-new-declarator is erroneous
           Product: clang
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++14
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

Created attachment 14009
  --> http://llvm.org/bugs/attachment.cgi?id=14009&action=edit
clang++ -v

The both sample codes below should cause compilationn error but they are
compiled successfully.

========================== sample code ==========================
int main()
{
    constexpr int i = -1;
    int* p = new int[i];
    delete[] p;
}
========================== sample code ==========================
cf. http://melpon.org/wandbox/permlink/TLTsz1iiAVM8DbV0

========================== sample code ==========================
int main()
{
    constexpr int i = 1;
    int* p = new int[i]{ 1, 2 };
    delete[] p;
}
========================== sample code ==========================
cf. http://melpon.org/wandbox/permlink/mEhdOsjtC2ztiFbb


Tthe C++14 standard 5.3.4[expr.new]/p.7 says,

  The expression in a noptr-new-declarator is erroneous if:

    --- the expression is of non-class type and its value before converting to
        std::size_t is less than zero;

    ...

    --- the new-initializer is a braced-init-list and the number of array
elements
        for which initializers are provided (including the terminating '\0' in
a
        string literal (2.13.5)) exceeds the number of elements to initialize.

  If the expression, after converting to std::size_t, is a core constant
expression
  and the expression is erroneous, the program is ill-formed.  ...


So, I think that the sample codes above should cause compilation error.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to