[PATCH] Instantiate static constexpr member function of a local struct in a function template earlier.
Michael Park
mcypark at gmail.com
Tue Apr 28 12:14:49 PDT 2015
Thanks for bringing this up Richard!
we reject the corresponding non-template case
>
It looks like we *correctly* reject the non-template case. The GCC folks
ran into that case and declared it invalid:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51080.
but accept the corresponding non-local class template case.
>
In terms of standardese, I haven't dug deep enough to determine whether
this case is valid or not. Perhaps you know the answer to this already?
In terms of our implementation, given that the non-template case is
ill-formed:
struct X {
> static constexpr int get() { return 42; }
int arr[get()]; // ill-formed: get() not defined here.
> }; // get() is defined here.
It makes sense to me that the following would not work either:
void f() {
struct X {
> static constexpr int get() { return 42; }
> int arr[get()];
> }
> }
Given that the class template case works (again, not sure about the
standardese):
> template <typename>
struct X {
static constexpr int get() { return 42; }
int arr[get()];
};
template class X<void>;
I think the following should work also:
template <typename>
void f() {
struct X {
> static constexpr int get() { return 42; }
> int arr[get()];
> }
> }
I think we need to distinguish the 2 cases (1) a local class enclosed in a
non-template function and (2) a local class enclosed in a function
template. A local class within a non-template function would behave
similarly to a non-template class whereas a local class within a function
template would behave similarly to a class template. Currently we seem to
treat a local class similar to a non-template class whether it's enclosed
in a non-template function or a function template.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150428/731b4d13/attachment.html>
More information about the cfe-commits
mailing list