I have the following class
#ifndef TEST_SUITE_BASE_H#define TEST_SUITE_BASE_H#include <stdint.h>#include <cpu.h>#include <io.h>namespace test {class Test_suite_base{public: using test_suite_base_func = const Test_suite_base (*) (); static constexpr const Test_suite_base test_suite(); static constexpr uint8_t size(); static const Test_suite_base from_index(uint8_t index_); Test_suite_base& operator=(const Test_suite_base& rhs) = default; constexpr Device_address value() const;private: constexpr explicit Test_suite_base(Device_address value_); Device_address val;};constexpr Test_suite_base::test_suite_base(Device_address value_) : val(value_) {}constexpr Device_address Test_suite_base::value() const { return val; }constexpr const Test_suite_base Test_suite_base::test_suite() { return Test_suite_base(reinterpret_cast<Device_address>(0x10009000)); }constexpr Test_suite_base::test_suite_base_func test_suite_base_arr[] = {&Test_suite_base::test_suite};inline const Test_suite_base Test_suite_base::from_index(uint8_t index_){ return test_suite_base_arr[index_]();}constexpr uint8_t Test_suite_base::size() { return 1; }};#endif // TEST_SUITE_BASE_H
When I compile and run the code, I get no errors and the code executes just fine.
However when I run Clang-tidy on it. I get the following warning/error.
test_suite_base.h:39:46: error: constexpr function never produces a constant expression [clang-diagnostic-invalid-constexpr]constexpr const Test_suite_base Test_suite_base::test_suite() { return Test_suite_base(reinterpret_cast<Device_address>(0x10009000)); } ^test_suite_base.h:39:80: note: reinterpret_cast is not allowed in a constant expressionconstexpr const Test_suite_base Test_suite_base::test_suite() { return Test_suite_base(reinterpret_cast<Device_address>(0x10009000)); }
I'm a bit unsure if its a "clang-tidy" problem or a serious one. Because I can execute my code without problems. The code above is autogenerated trough scripting so changing the code will have fallout in other places.
Regards