Lazy template instantiation of unused reference arguments

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Lazy template instantiation of unused reference arguments

suyash singh via cfe-dev
Hi,

I'm having some issue with "opaque struct" being instantiated by Clang on unused reference arguments that have template types (that's an annoyance but not the topic of this email). I assume Clang decide to be lazy on the instantiation of unused arguments to save compile time.

But now I am wondering if that is actually a legal behavior in C++.
For example, the following code does not trigger the static_assert:

template<int N>
struct test {
static_assert(N == 42);
};

int foo(test<69> &a) {
return 0;
}

Is that expected/desired behavior? (if you add "a = a;" then it will properly trigger it)

--
Alexandre Isoard

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Lazy template instantiation of unused reference arguments

suyash singh via cfe-dev
On Wed, 19 Feb 2020 at 17:56, Alexandre Isoard via cfe-dev <[hidden email]> wrote:
Hi,

I'm having some issue with "opaque struct" being instantiated by Clang on unused reference arguments that have template types (that's an annoyance but not the topic of this email). I assume Clang decide to be lazy on the instantiation of unused arguments to save compile time.

But now I am wondering if that is actually a legal behavior in C++.
For example, the following code does not trigger the static_assert:

template<int N>
struct test {
static_assert(N == 42);
};

int foo(test<69> &a) {
return 0;
}

Is that expected/desired behavior? (if you add "a = a;" then it will properly trigger it)

The C++ language rules do not permit instantiation of test<69> in this program. See http://eel.is/c++draft/temp.inst#1.sentence-1 -- this program does not require test<69> to be a complete type, and its definition doesn't affect the semantics of the program, so instantiation of that class is neither required nor permitted here. 

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Lazy template instantiation of unused reference arguments

suyash singh via cfe-dev
Oh, wow, I learn every day.

Thank you for the pointer.

On Wed, Feb 19, 2020, 18:26 Richard Smith <[hidden email]> wrote:
On Wed, 19 Feb 2020 at 17:56, Alexandre Isoard via cfe-dev <[hidden email]> wrote:
Hi,

I'm having some issue with "opaque struct" being instantiated by Clang on unused reference arguments that have template types (that's an annoyance but not the topic of this email). I assume Clang decide to be lazy on the instantiation of unused arguments to save compile time.

But now I am wondering if that is actually a legal behavior in C++.
For example, the following code does not trigger the static_assert:

template<int N>
struct test {
static_assert(N == 42);
};

int foo(test<69> &a) {
return 0;
}

Is that expected/desired behavior? (if you add "a = a;" then it will properly trigger it)

The C++ language rules do not permit instantiation of test<69> in this program. See http://eel.is/c++draft/temp.inst#1.sentence-1 -- this program does not require test<69> to be a complete type, and its definition doesn't affect the semantics of the program, so instantiation of that class is neither required nor permitted here. 

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev