4

The following code will compile with FIXME defined, but not without. The compiler in question is visual studio 2013.

#include <functional>

#ifdef FIXME
namespace unrelated_namespace {
    struct ned {};
}
#endif

namespace something {
    struct do_something {
        template <typename T>
        do_something(T f) {}
    };
}

using namespace something;

do_something my_something([](){
    std::function<void(void)> inner([]{});
});

#ifndef FIXME
namespace unrelated_namespace {
    struct ned {};
}
#endif

The errors are as follows:

Error   2   error C2888: '<lambda_22ffa30be171afdd76e6bc1bf85e9dd7>::()::<lambda_cac50c1ea5c52e062ca61c564ead686c>' :
  symbol cannot be defined within namespace 'unrelated_namespace'
  C:\hudson\workspace\phtest_build_windows\replication_dev\kernel\foe\test\serialize_unit.cpp   20  1   foe

Error   3   error C2888: '<lambda_22ffa30be171afdd76e6bc1bf85e9dd7>::<helper_func_cdecl>::<lambda_8c92b136dc3e83c8e0db25c06e4203d5>' : 
  symbol cannot be defined within namespace 'unrelated_namespace'   
  C:\hudson\workspace\phtest_build_windows\replication_dev\kernel\foe\test\serialize_unit.cpp   20  1   foe

Error   3   error C2888: '<lambda_22ffa30be171afdd76e6bc1bf85e9dd7>::<helper_func_cdecl>::<lambda_8c92b136dc3e83c8e0db25c06e4203d5>' :
  symbol cannot be defined within namespace 'unrelated_namespace'   
  C:\hudson\workspace\phtest_build_windows\replication_dev\kernel\foe\test\serialize_unit.cpp   20  1   foe

G++ eats the code with no complaint (e.g. http://ideone.com/ZEPYE7).

Is there an explanation for this behaviour other than a compiler bug?

5
  • "G++ eats the code with no complaint." here gcc errors out on both variants... what version are you using? can you show a link to ideone where it works?
    – PlasmaHH
    Sep 19, 2014 at 15:00
  • I've added a link to ideone. Locally I compiled with gcc 4.8: g++ -pedantic -std=c++11 x.cpp.
    – Ned
    Sep 19, 2014 at 15:11
  • Ah, when adding the {} it compiles here too. Are you sure you fed the code with them to visual studio, or did you try it there without?
    – PlasmaHH
    Sep 19, 2014 at 15:17
  • Ok, apologies for the typo. No, I hadn't given VS the braces. I have now and the result is the same.
    – Ned
    Sep 19, 2014 at 15:21
  • 1
    I'm coming across the same issue in VS2017 - anyone shed any light on this?
    – schuess
    Jul 7, 2017 at 0:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.