[cfe-dev] noexcept and local variables

Sebastian Redl sebastian.redl at getdesigned.at
Fri May 27 06:36:56 PDT 2011


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.

Sebastian



More information about the cfe-dev mailing list