[llvm-bugs] [Bug 46308] New: Not a constant expression: comparison between unequal pointers to void has unspecified result

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jun 12 16:15:45 PDT 2020


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

            Bug ID: 46308
           Summary: Not a constant expression: comparison between unequal
                    pointers to void has unspecified result
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Keywords: compile-fail
          Severity: normal
          Priority: P
         Component: C++14
          Assignee: unassignedclangbugs at nondot.org
          Reporter: language.lawyer at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

About the following program:


struct S
{
        int i;
        int j;
};

constexpr S s {};

static_assert(&s.i < (void*)&s.j);



clang in C++14, C++17 and C++2a modes says that the expression in static_assert
is not a constant expression:

$ clang++ prog.cc -std=c++14
prog.cc:9:15: error: static_assert expression is not an integral constant
expression
static_assert(&s.i < (void*)&s.j, "");
              ^~~~~~~~~~~~~~~~~~
prog.cc:9:20: note: comparison between unequal pointers to void has unspecified
result
static_assert(&s.i < (void*)&s.j, "");
                   ^

(https://wandbox.org/permlink/IXwrV0M75To3wUUB)

However, the special handling of pointers to void has been removed from
[expr.rel] by http://wg21.link/n3624 (applied in [1]), so the result of
comparing unequal pointers to void is no longer unspecified, so the expression
is a constant expression.



[1]
https://github.com/cplusplus/draft/commit/89281b5795f47b9196c37ce8008b4873a76e90ef#diff-64a673ab7a20068092a4cf86b36f4334L3647-L3650

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200612/30a489e7/attachment-0001.html>


More information about the llvm-bugs mailing list