https://bugs.llvm.org/show_bug.cgi?id=50036
Bug ID: 50036
Summary: Comparing pointer into string literal is not a
constant expression
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: unassignedclangb...@nondot.org
Reporter: davidfromonl...@gmail.com
CC: blitzrak...@gmail.com, dgre...@apple.com,
erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
richard-l...@metafoo.co.uk
The following well-formed translation unit
```
static_assert(+"a" != +"b");
```
is rejected by clang with the error message
```
<source>:1:20: error: static_assert expression is not an integral constant
expression
static_assert(+"a" != +"b");
~~~~~^~~~~~~
1 error generated.
Compiler returned: 1
```
>From the standard:
"An expression E is a core constant expression unless the evaluation of E,
following the rules of the abstract machine ([intro.execution]), would evaluate
one of the following: ... a three-way comparison ([expr.spaceship]), relational
([expr.rel]), or equality ([expr.eq]) operator where the result is
unspecified;" (http://eel.is/c++draft/expr.const#5.23)
And:
If at least one of the operands is a pointer, pointer conversions, function
pointer conversions, and qualification conversions are performed on both
operands to bring them to their composite pointer type.
Comparing pointers is defined as follows:
- If one pointer represents the address of a complete object, and another
pointer represents the address one past the last element of a different
complete object,75 the result of the comparison is unspecified.
- Otherwise, if the pointers are both null, both point to the same function,
or both represent the same address, they compare equal.
- Otherwise, the pointers compare unequal.
(http://eel.is/c++draft/expr.eq#3)
The unspecified condition does not apply, so this should be accepted.
See it live: https://godbolt.org/z/vrWh54KM1
--
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