[llvm-bugs] [Bug 52420] New: Clang fails to compile valid template for x86_64-pc-windows-msvc target

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Nov 5 09:00:53 PDT 2021


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

            Bug ID: 52420
           Summary: Clang fails to compile valid template for
                    x86_64-pc-windows-msvc target
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: epastor at google.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

Originally reported by Anthony Erlinger:

The following valid code fails to compile with -target x86_64-pc-windows-msvc:

template <typename A>
struct S {
    void f() {
        const int B = 5;
        struct C {
            int g() {
                return B; // <-- error: use of undeclared identifier 'B'
            }
        };
    }
};

void test() {
    S<int>().f();
}

Invocation: clang -target x86_64-pc-windows-msvc example.cc

Compiler output:
<source>:7:24: error: use of undeclared identifier 'B'
                return B;
                       ^
<source>:14:14: note: in instantiation of member function 'S<int>::f' requested
here
    S<int>().f();
1 error generated.
Compiler returned: 1

Godbolt example showing failure in clang vs successful compile in MSVC:
https://godbolt.org/z/h6431Wbh5

This is fixed with the flags /Zc:twoPhase or -fno-delayed-template-parsing, but
works in MSVC itself, so it's clearly a bug in how we emulate MSVC's
non-compliant template instantiation.

-- 
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/20211105/880cb24e/attachment.html>


More information about the llvm-bugs mailing list