Skip to content

<functional>: Clang error when calling target() on a const function #3843

Description

Repros with VS 2022 17.7 Preview 2 x64 containing Clang 16.0.1.

D:\GitHub\STL\out\x64>type meow.cpp
#include <cassert>
#include <functional>
using namespace std;

int main() {
    const function<void()> f;

    assert(f.target<void()>() == nullptr);
}
D:\GitHub\STL\out\x64>cl /EHsc /nologo /W4 /MTd /Od meow.cpp && meow
meow.cpp

D:\GitHub\STL\out\x64>clang-cl /EHsc /nologo /W4 /MTd /Od meow.cpp && meow
In file included from meow.cpp:2:
D:\GitHub\STL\out\x64\out\inc\functional(1142,16): error: reinterpret_cast from 'const void *' to 'void (*)()' casts
      away qualifiers
        return reinterpret_cast<const _Fx*>(this->_Target(typeid(_Fx)));
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
meow.cpp(8,14): note: in instantiation of function template specialization 'std::function<void ()>::target<void ()>'
      requested here
    assert(f.target<void()>() == nullptr);
             ^
1 error generated.

Reduced from the original report DevCom-10402530 VSO-1843867 AB#1843867 "std::function::target is broken on clang-cl when called on const objects".

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions