Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation fails with error: arithmetic on a pointer to an incomplete type #2844

Open
rnburn opened this issue Mar 13, 2024 · 3 comments
Open

Comments

@rnburn
Copy link

rnburn commented Mar 13, 2024

Describe the bug

I'm trying to compile test cases that include

#include "catch2/catch_test_macros.hpp"
#include "catch2/catch_approx.hpp"
#include "catch2/generators/catch_generators.hpp"

but compilation fails with

ERROR: /home/rnburn/.cache/bazel/_bazel_rnburn/d8123aa23bfc2a43914d6af343f507b1/external/com_github_catchorg_catch2/BUILD.bazel:74:11: Compiling src/catch2/internal/catch_test_case_registry_impl.cpp failed: (Exit 1): clang-19 failed: error executing command (from target @com_github_catchorg_catch2//:catch2) /nix/store/j9c9vnnzdiwsr7qwx1a9r0a22qk6q66p-clang/bin/clang-19 -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -Wunused-but-set-parameter -Wno-free-nonheap-object ... (remaining 31 arguments skipped)
In file included from external/com_github_catchorg_catch2/src/catch2/internal/catch_test_case_registry_impl.cpp:8:
In file included from external/com_github_catchorg_catch2/src/catch2/internal/catch_test_case_registry_impl.hpp:11:
In file included from external/com_github_catchorg_catch2/src/catch2/interfaces/catch_interfaces_testcase.hpp:11:
/nix/store/j9c9vnnzdiwsr7qwx1a9r0a22qk6q66p-clang/bin/../include/c++/v1/vector:927:60: error: arithmetic on a pointer to an incomplete type 'Catch::TestCaseHandle'
  927 |       __alloc_traits::destroy(__alloc(), std::__to_address(--__soon_to_be_end));
      |                                                            ^ ~~~~~~~~~~~~~~~~
/nix/store/j9c9vnnzdiwsr7qwx1a9r0a22qk6q66p-clang/bin/../include/c++/v1/vector:921:5: note: in instantiation of member function 'std::vector<Catch::TestCaseHandle>::__base_destruct_at_end' requested here
  921 |     __base_destruct_at_end(this->__begin_);
      |     ^
/nix/store/j9c9vnnzdiwsr7qwx1a9r0a22qk6q66p-clang/bin/../include/c++/v1/vector:491:16: note: in instantiation of member function 'std::vector<Catch::TestCaseHandle>::__clear' requested here
  491 |         __vec_.__clear();
      |                ^
/nix/store/j9c9vnnzdiwsr7qwx1a9r0a22qk6q66p-clang/bin/../include/c++/v1/vector:502:67: note: in instantiation of member function 'std::vector<Catch::TestCaseHandle>::__destroy_vector::operator()' requested here
  502 |   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~vector() { __destroy_vector (*this)(); }
      |                                                                   ^
external/com_github_catchorg_catch2/src/catch2/internal/catch_test_case_registry_impl.hpp:31:11: note: in instantiation of member function 'std::vector<Catch::TestCaseHandle>::~vector' requested here
   31 |     class TestRegistry : public ITestCaseRegistry {
      |           ^
external/com_github_catchorg_catch2/src/catch2/internal/catch_test_case_registry_impl.hpp:31:11: note: in implicit destructor for 'Catch::TestRegistry' first required here
external/com_github_catchorg_catch2/src/catch2/interfaces/catch_interfaces_testcase.hpp:16:11: note: forward declaration of 'Catch::TestCaseHandle'
   16 |     class TestCaseHandle;
      |           ^
In file included from external/com_github_catchorg_catch2/src/catch2/internal/catch_test_case_registry_impl.cpp:8:
In file included from external/com_github_catchorg_catch2/src/catch2/internal/catch_test_case_registry_impl.hpp:11:
In file included from external/com_github_catchorg_catch2/src/catch2/interfaces/catch_interfaces_testcase.hpp:11:
In file included from /nix/store/j9c9vnnzdiwsr7qwx1a9r0a22qk6q66p-clang/bin/../include/c++/v1/vector:325:
In file included from /nix/store/j9c9vnnzdiwsr7qwx1a9r0a22qk6q66p-clang/bin/../include/c++/v1/__format/formatter_bool.h:20:
In file included from /nix/store/j9c9vnnzdiwsr7qwx1a9r0a22qk6q66p-clang/bin/../include/c++/v1/__format/formatter_integral.h:21:
In file included from /nix/store/j9c9vnnzdiwsr7qwx1a9r0a22qk6q66p-clang/bin/../include/c++/v1/__format/formatter_output.h:22:
In file included from /nix/store/j9c9vnnzdiwsr7qwx1a9r0a22qk6q66p-clang/bin/../include/c++/v1/__format/parser_std_format_spec.h:39:
In file included from /nix/store/j9c9vnnzdiwsr7qwx1a9r0a22qk6q66p-clang/bin/../include/c++/v1/string:588:
/nix/store/j9c9vnnzdiwsr7qwx1a9r0a22qk6q66p-clang/bin/../include/c++/v1/__memory/allocator.h:139:50: error: invalid application of 'sizeof' to an incomplete type 'Catch::TestCaseHandle'
  139 |       std::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
      |                                                  ^~~~~~~~~~~
/nix/store/j9c9vnnzdiwsr7qwx1a9r0a22qk6q66p-clang/bin/../include/c++/v1/__memory/allocator_traits.h:313:9: note: in instantiation of member function 'std::allocator<Catch::TestCaseHandle>::deallocate' requested here
  313 |     __a.deallocate(__p, __n);
      |         ^
/nix/store/j9c9vnnzdiwsr7qwx1a9r0a22qk6q66p-clang/bin/../include/c++/v1/vector:493:25: note: in instantiation of member function 'std::allocator_traits<std::allocator<Catch::TestCaseHandle>>::deallocate' requested here
  493 |         __alloc_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.capacity());
      |                         ^
/nix/store/j9c9vnnzdiwsr7qwx1a9r0a22qk6q66p-clang/bin/../include/c++/v1/vector:502:67: note: in instantiation of member function 'std::vector<Catch::TestCaseHandle>::__destroy_vector::operator()' requested here
  502 |   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~vector() { __destroy_vector (*this)(); }
      |                                                                   ^
external/com_github_catchorg_catch2/src/catch2/internal/catch_test_case_registry_impl.hpp:31:11: note: in instantiation of member function 'std::vector<Catch::TestCaseHandle>::~vector' requested here
   31 |     class TestRegistry : public ITestCaseRegistry {
      |           ^
external/com_github_catchorg_catch2/src/catch2/internal/catch_test_case_registry_impl.hpp:31:11: note: in implicit destructor for 'Catch::TestRegistry' first required here
external/com_github_catchorg_catch2/src/catch2/interfaces/catch_interfaces_testcase.hpp:16:11: note: forward declaration of 'Catch::TestCaseHandle'
   16 |     class TestCaseHandle;
      |           ^
In file included from external/com_github_catchorg_catch2/src/catch2/internal/catch_test_case_registry_impl.cpp:8:
In file included from external/com_github_catchorg_catch2/src/catch2/internal/catch_test_case_registry_impl.hpp:11:
In file included from external/com_github_catchorg_catch2/src/catch2/interfaces/catch_interfaces_testcase.hpp:11:
/nix/store/j9c9vnnzdiwsr7qwx1a9r0a22qk6q66p-clang/bin/../include/c++/v1/vector:599:47: error: arithmetic on a pointer to an incomplete type 'Catch::TestCaseHandle'
  599 |     return static_cast<size_type>(__end_cap() - this->__begin_);
      |                                   ~~~~~~~~~~~ ^
/nix/store/j9c9vnnzdiwsr7qwx1a9r0a22qk6q66p-clang/bin/../include/c++/v1/vector:493:78: note: in instantiation of member function 'std::vector<Catch::TestCaseHandle>::capacity' requested here
  493 |         __alloc_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.capacity());
      |                                                                              ^
/nix/store/j9c9vnnzdiwsr7qwx1a9r0a22qk6q66p-clang/bin/../include/c++/v1/vector:502:67: note: in instantiation of member function 'std::vector<Catch::TestCaseHandle>::__destroy_vector::operator()' requested here
  502 |   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~vector() { __destroy_vector (*this)(); }
      |                                                                   ^
external/com_github_catchorg_catch2/src/catch2/internal/catch_test_case_registry_impl.hpp:31:11: note: in instantiation of member function 'std::vector<Catch::TestCaseHandle>::~vector' requested here
   31 |     class TestRegistry : public ITestCaseRegistry {
      |           ^
external/com_github_catchorg_catch2/src/catch2/internal/catch_test_case_registry_impl.hpp:31:11: note: in implicit destructor for 'Catch::TestRegistry' first required here
external/com_github_catchorg_catch2/src/catch2/interfaces/catch_interfaces_testcase.hpp:16:11: note: forward declaration of 'Catch::TestCaseHandle'
   16 |     class TestCaseHandle;
      |           ^
3 errors generated.
INFO: Elapsed time: 4.779s, Critical Path: 3.77s
INFO: 27 processes: 17 internal, 10 local.
FAILED: Build did NOT complete successfully

I'm running into this error after trying to make an upgrade to clang. (The earlier version I was using didn't have this problem).

Here's the compiler details

clang++ --version
clang version 19.0.0git
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /nix/store/j9c9vnnzdiwsr7qwx1a9r0a22qk6q66p-clang/bin

I'm compiling with -stdlib=libc++ and -std=c++2b.

Expected behavior

Compilation doesn't fail.

Reproduction steps

I don't have a smaller reproducer, but you could reproduce by following the build step of this project with nix using this particular commit: https://github.com/spaceandtimelabs/blitzar/tree/e464a350c99705933f9c07a77a3f8d0a3fc21d22?tab=readme-ov-file#usage

Platform information:

This is the version of catch2 I'm trying

git_repository(
    name = "com_github_catchorg_catch2",
    commit = "a2a3c55",
    remote = "https://github.com/catchorg/Catch2",
)

And here is a nix expression compiler enviornment: https://github.com/spaceandtimelabs/blitzar/blob/update-versions/nix/clang.nix

Additional context
Add any other context about the problem here.

@p4vook
Copy link

p4vook commented Mar 26, 2024

Perhaps, you didn't include some needed header you use. Could you try with including catch_all.hpp?

@bruno-j-nicoletti
Copy link

I've just upgrade to clang-19 and I'm getting the same error.

@bruno-j-nicoletti
Copy link

Perhaps, you didn't include some needed header you use. Could you try with including catch_all.hpp?

The error is in a Catch2 .cpp file, not in client code. catch_registry_hub.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants