<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Comparing pointer into string literal is not a constant expression"
href="https://bugs.llvm.org/show_bug.cgi?id=50036">50036</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Comparing pointer into string literal is not a constant expression
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>davidfromonline@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>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;" (<a href="http://eel.is/c++draft/expr.const#5.23">http://eel.is/c++draft/expr.const#5.23</a>)
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.
(<a href="http://eel.is/c++draft/expr.eq#3">http://eel.is/c++draft/expr.eq#3</a>)
The unspecified condition does not apply, so this should be accepted.
See it live: <a href="https://godbolt.org/z/vrWh54KM1">https://godbolt.org/z/vrWh54KM1</a></pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>