Linker scenarios When Using constexpr Functions with std::optional in C++20
I've encountered a strange issue with This might be a silly question, but I keep running into I've been working on this all day and Quick question that's been bugging me - I'm working with a linker behavior when trying to use `std::optional` in combination with a `constexpr` function in my C++20 project. The code compiles fine but fails during the linking stage with the following behavior message: ``` undefined reference to `myOptionalFunction()' ``` Here's a simplified version of my code that reproduces the scenario: ```cpp #include <optional> #include <iostream> constexpr int myOptionalFunction() { return 42; } std::optional<int> createOptional() { return myOptionalFunction(); } int main() { auto opt = createOptional(); if (opt) { std::cout << "Optional contains: " << *opt << '\n'; } return 0; } ``` I've double-checked that Iām compiling with `-std=c++20`, and I'm using GCC 11.2.0. It seems like there's something going wrong with the linkage of the `constexpr` function when it's used inside `std::optional`. I've tried moving the function definition to a header file and including it, but the linker behavior still continues. Is this a known scenario with `std::optional`, or am I missing something in how I should be using `constexpr` functions in this context? Any insights or suggestions on how to resolve this would be greatly appreciated! My development environment is Linux. What's the best practice here? I'm developing on CentOS with C++. Am I missing something obvious? I've been using C++ for about a year now. I appreciate any insights! I'm using C++ stable in this project. Thanks for any help you can provide! I'm using C++ 3.9 in this project. Could this be a known issue?