[llvm-bugs] [Bug 50290] New: Cannot use fields in requires expression before declaration

via llvm-bugs llvm-bugs at lists.llvm.org
Mon May 10 14:20:18 PDT 2021


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

            Bug ID: 50290
           Summary: Cannot use fields in requires expression before
                    declaration
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: llvm-bugs at admitriev.name
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

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: 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
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.

-- 
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/20210510/81734a82/attachment.html>


More information about the llvm-bugs mailing list