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

vector deduction guides warning: variable length arrays in C++ are a Clang extension #849

Open
AlexeySachkov opened this issue Jan 9, 2024 · 0 comments

Comments

@AlexeySachkov
Copy link
Contributor

template <typename T>
class check_vec_deduction {
public:
void operator()(const std::string& type) {
type_name = type;
T data[max_size];

If I understand correctly, we need to replace const with constexpr static here:

private:
const int max_size = 16;

The fact that class member variable is defined as const doesn't make it into a compile-time-known constant, it only means that it is immutable.

Build log:

[834/1195] Building CXX object tests/vector_deduction_guides/CMakeFiles/test_vector_deduction_guides_objects.dir/vec_deduction_guides.cpp.o
../tests/vector_deduction_guides/vec_deduction_guides.cpp:36:12: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   36 |     T data[max_size];
      |            ^~~~~~~~
../tests/vector_deduction_guides/../common/../common/type_coverage.h:404:5: note: in instantiation of member function 'vec_deduction_guides::check_vec_deduction<float>::operator()' requested here
  404 |   ((action<types, actionArgsT...>{}(std::forward<argsT>(args)...,
      |     ^
../tests/vector_deduction_guides/vec_deduction_guides.cpp:90:3: note: in instantiation of function template specialization 'for_all_types<vec_deduction_guides::check_vec_deduction, char, signed char, unsigned char, short, unsigned
short, unsigned int, long, unsigned long, long long, unsigned long long, bool, float>' requested here
   90 |   for_all_types<check_vec_deduction>(deduction::vector_types);
      |   ^
../tests/vector_deduction_guides/../common/disabled_for_test_case.h:42:3: note: expanded from macro 'DISABLED_FOR_TEST_CASE'
   42 |   INTERNAL_CTS_DISABLED_FOR_TEST_CASE(__VA_ARGS__)
      |   ^
../tests/vector_deduction_guides/../common/disabled_for_test_case.h:130:40: note: expanded from macro 'INTERNAL_CTS_DISABLED_FOR_TEST_CASE'
  130 |   INTERNAL_CTS_MAYBE_DISABLE_TEST_CASE(INTERNAL_CTS_ENABLED_TEST_CASE, \
      |                                        ^
../tests/vector_deduction_guides/vec_deduction_guides.cpp:36:12: note: implicit use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function
   36 |     T data[max_size];
      |            ^
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

1 participant