Skip to content

error: invalid application of 'sizeof' to a function type; with clang++/llvm-20.1.5 #142118

@peledins-zimperium

Description

@peledins-zimperium

Repro:

% cat a.cpp
#include <memory>
struct B;
void deleter(B *){};
struct A
{
    A() : handle(nullptr,deleter) {}
    std::unique_ptr<B, void (&)(B*)> handle;
};

int main()
{
    A a;
}
% /opt/homebrew/Cellar/llvm@19/19.1.7/bin/clang++ ./a.cpp
# --> OK
% /opt/homebrew/Cellar/llvm/20.1.5/bin/clang++ ./a.cpp             
In file included from ./a.cpp:1:
In file included from /opt/homebrew/Cellar/llvm/20.1.5/bin/../include/c++/v1/memory:947:
In file included from /opt/homebrew/Cellar/llvm/20.1.5/bin/../include/c++/v1/__memory/inout_ptr.h:16:
In file included from /opt/homebrew/Cellar/llvm/20.1.5/bin/../include/c++/v1/__memory/shared_ptr.h:30:
/opt/homebrew/Cellar/llvm/20.1.5/bin/../include/c++/v1/__memory/compressed_pair.h:68:57: error: invalid application of 'sizeof' to a function type
   68 |                          is_reference<_ToPad>::value || sizeof(_ToPad) == __datasizeof_v<_ToPad>)>
      |                                                         ^~~~~~~~~~~~~~
/opt/homebrew/Cellar/llvm/20.1.5/bin/../include/c++/v1/__memory/unique_ptr.h:162:3: note: in instantiation of default argument for '__compressed_pair_padding<deleter_type>' required here
  162 |   _LIBCPP_COMPRESSED_PAIR(pointer, __ptr_, deleter_type, __deleter_);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/homebrew/Cellar/llvm/20.1.5/bin/../include/c++/v1/__memory/compressed_pair.h:80:38: note: expanded from macro '_LIBCPP_COMPRESSED_PAIR'
   80 |     _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T2> _LIBCPP_CONCAT3(__padding2_, __LINE__, _)
      |                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./a.cpp:7:38: note: in instantiation of template class 'std::unique_ptr<B, void (&)(B *)>' requested here
    7 |     std::unique_ptr<B, void (&)(B*)> handle;
      |                                      ^
1 error generated.

19.1.7 seems to be working, 20.1.5.-no.

Metadata

Metadata

Assignees

No one assigned

    Labels

    libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.regression:20Regression in 20 release

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions