Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Passing templated function-local class as template parameter causes infinite recursion in instantiation #47808

Open Quuxplusone opened 3 years ago

Quuxplusone commented 3 years ago
Bugzilla Link PR48839
Status CONFIRMED
Importance P normal
Reported by Mital Ashok (mital.vaja@googlemail.com)
Reported on 2021-01-21 14:57:01 -0800
Last modified on 2021-06-25 03:16:21 -0700
Version trunk
Hardware All All
CC blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, futogergely@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
The following compiles with gcc but does not with clang:

    template<typename T>
    void construct() {
        T(0);
    }

    template<typename T>
    void tester() {
        struct d {
            void test() {
                construct<d>();
            }
            constexpr d(T b) : a(b) {}
            T a;
        };
    }

    int main() {
        tester<int>();
    }

link: https://godbolt.org/z/jd41rr

It fails with "fatal error: recursive template instantiation exceeded maximum
depth of 1024"
Quuxplusone commented 3 years ago

From the diagnostics:

:8:12: note: in instantiation of member function 'tester()::d::d(int)::d::test' requested here

... it looks like we're creating a duplicate local struct d within the d::d(int) constructor (and so on, recursively).

Quuxplusone commented 3 years ago

This appears to have regressed between Clang 3.3 and 3.4.

Quuxplusone commented 3 years ago

Hi, I'm new to clang, but do you mind if I start working on this? Thanks, Gergely

Quuxplusone commented 3 years ago

https://reviews.llvm.org/D103595

Quuxplusone commented 3 years ago
Different issue, but this should also work right?

template<typename T>

void construct() {
    constexpr T t(0);
}

template<typename T>
void tester() {
    struct d {
        void test() {
            construct<d>();
        }
        constexpr d(T b) : a(b) {}
        T a;
    };
}

int main() {
    tester<int>();
}

clang fails with following error:
<source>:3:17: error: constexpr variable 't' must be initialized by a constant
expression
    constexpr T t(0);
                ^~~~
link: https://godbolt.org/z/93ecvjE5h