Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use fields in requires expression before declaration #49634

Closed
AlexeyDmitriev opened this issue May 10, 2021 · 1 comment
Closed

Cannot use fields in requires expression before declaration #49634

AlexeyDmitriev opened this issue May 10, 2021 · 1 comment
Labels
bugzilla Issues migrated from bugzilla clang Clang issues not falling into any other category concepts C++20 concepts duplicate Resolved as duplicate

Comments

@AlexeyDmitriev
Copy link

Bugzilla Link 50290
Resolution DUPLICATE
Resolved on Oct 18, 2021 08:39
Version trunk
OS All
CC @AaronBallman,@zygoloid

Extended Description

If I use field (or this->field) inside the requires requires, clang supposes it not existent.

Code:

struct S {
double result() {
return 0;
}
};
template
class Outer {
public:
double result() requires requires {this->inner.result();} {
return inner.result();
}
Inner inner;
};
double foo() {
Outer c;
return c.result();
}

Compiler explorer link: https://godbolt.org/z/zdcTjYoE8

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 (https://github.com/llvm/llvm-project.git 0f8854f)
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++
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.

@AaronBallman
Copy link
Collaborator

*** This bug has been marked as a duplicate of bug #44178 ***

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@Quuxplusone Quuxplusone added the concepts C++20 concepts label Jan 16, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang Clang issues not falling into any other category concepts C++20 concepts duplicate Resolved as duplicate
Projects
Status: No status
Development

No branches or pull requests

3 participants