[cfe-dev] noexcept and local variables
Howard Hinnant
hhinnant at apple.com
Fri May 27 08:11:58 PDT 2011
On May 27, 2011, at 9:36 AM, Sebastian Redl wrote:
> On 27.05.2011 01:53, Howard Hinnant wrote:
>> Is code like this supposed to work?
>>
>> template<class T>
>> class A
>> {
>> T t_;
>> public:
>> void swap(A& y) noexcept(noexcept(swap(t_, y.t_)));
>> };
>>
>> template<class T>
>> void
>> swap(A<T>& x, A<T>& y) noexcept(noexcept(x.swap(y)));
>>
>> int main()
>> {
>> A<int> i, j;
>> swap(i, j);
>> }
>>
>> It currently gives errors:
>>
>> test.cpp:6:49: error: member access into incomplete type 'A<int>'
>> void swap(A& y) noexcept(noexcept(swap(t_, y.t_)));
>
> Clang bug. This is supposed to work per 9.2p2. I don't know what part of
> the class is visible at that point, though. That is, if t_ was declared
> after swap(), would the code still be valid? I don't think it would be,
> but the standard references for this stuff are all over the place.
> (Also, blargh! This will be horrible to fix.)
>> test.cpp:11:42: error: reference to local variable 'x' declared in enclosed function 'swap'
>> swap(A<T>& x, A<T>& y) noexcept(noexcept(x.swap(y)));
>> ^
> I don't even understand what that's supposed to mean. Even if this is
> actually invalid (and I don't think it is), the error message alone must
> be considered a bug.
Thanks for looking into this Sebastian.
I've checked in libc++ workarounds for this. And I've checked in separate bugzilla's for each case, as it sounds like it may be more practical to fix one than the other:
http://llvm.org/bugs/show_bug.cgi?id=10035
http://llvm.org/bugs/show_bug.cgi?id=10036
Howard
More information about the cfe-dev
mailing list