On Tue, Apr 28, 2015 at 12:14 PM, Michael Park <[email protected]> wrote:
> Thanks for bringing this up Richard! > > we reject the corresponding non-template case >> > > It looks like we *correctly* reject the non-template case. > Right. > 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? > The answer is that we don't really know. It would be more consistent with the non-template case for it to be ill-formed (it also seems reasonable to say that you can't instantiate a member function until its class is complete), but the point of instantiation rules for constexpr functions aren't settled yet; this is part of DR1581 (still open). 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. >
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
