<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 - Cannot use fields in requires expression before declaration"
href="https://bugs.llvm.org/show_bug.cgi?id=50290">50290</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Cannot use fields in requires expression before declaration
</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>All
</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>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>llvm-bugs@admitriev.name
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>If I use field (or this->field) inside the requires requires, clang supposes it
not existent.
Code:
struct S {
double result() {
return 0;
}
};
template<typename Inner>
class Outer {
public:
double result() requires requires {this->inner.result();} {
return inner.result();
}
Inner inner;
};
double foo() {
Outer<S> c;
return c.result();
}
Compiler explorer link: <a href="https://godbolt.org/z/zdcTjYoE8">https://godbolt.org/z/zdcTjYoE8</a>
If I change this to
class Outer {
public:
double result() requires requires {this->inner.result();} {
return inner.result();
}
Inner inner;
};
, then it does work.
I expect original code to work because normally inside a class all variables
are considered (e.g return inner.result(); is fine), but maybe I am not
correct and there is wording that prohibits this code.
Note that gcc does compile this code (which I understand doesn't mean the code
is correct)
options I've used: -std=c++20
clang++ -v gives me
#1 with x86-64 clang (trunk)
clang version 13.0.0 (<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a>
0f8854f7f5d3e98f32eef7cfd09d5b8915a7d301)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-trunk/bin
Found candidate GCC installation:
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.0
Selected GCC installation:
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
(in-process)
"/opt/compiler-explorer/clang-trunk-20210510/bin/clang-13" -cc1 -triple
x86_64-unknown-linux-gnu -S -disable-free -disable-llvm-verifier
-discard-value-names -main-file-name example.cpp -mrelocation-model static
-mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases
-munwind-tables -target-cpu x86-64 -tune-cpu generic -mllvm
-treat-scalable-fixed-error-as-warning -debug-info-kind=limited
-dwarf-version=4 -debugger-tuning=gdb -v -fcoverage-compilation-dir=/app
-resource-dir /opt/compiler-explorer/clang-trunk-20210510/lib/clang/13.0.0
-isystem /opt/compiler-explorer/libs/outcome/single-header -internal-isystem
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.0/../../../../include/c++/12.0.0
-internal-isystem
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.0/../../../../include/c++/12.0.0/x86_64-linux-gnu
-internal-isystem
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.0/../../../../include/c++/12.0.0/backward
-internal-isystem
/opt/compiler-explorer/clang-trunk-20210510/lib/clang/13.0.0/include
-internal-isystem /usr/local/include -internal-isystem
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.0/../../../../x86_64-linux-gnu/include
-internal-externc-isystem /usr/include/x86_64-linux-gnu
-internal-externc-isystem /include -internal-externc-isystem /usr/include
-std=c++20 -fdeprecated-macro -fdebug-compilation-dir=/app -ferror-limit 19
-fgnuc-version=4.2.1 -fno-implicit-modules -fcxx-exceptions -fexceptions
-fcolor-diagnostics -mllvm --x86-asm-syntax=intel -faddrsig
-D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /app/output.s -x c++ <source>
clang -cc1 version 13.0.0 based upon LLVM 13.0.0git default target
x86_64-unknown-linux-gnu
ignoring nonexistent directory
"/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.0/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/opt/compiler-explorer/libs/outcome/single-header
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.0/../../../../include/c++/12.0.0
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.0/../../../../include/c++/12.0.0/x86_64-linux-gnu
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.0/../../../../include/c++/12.0.0/backward
/opt/compiler-explorer/clang-trunk-20210510/lib/clang/13.0.0/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.</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>