Why does this code using __LINE__ compile under MSVC in Release mode, but not in Debug mode?
- 阅读更多 关于 Why does this code using __LINE__ compile under MSVC in Release mode, but not in Debug mode?
问题 Consider this program: #include <iostream> template<bool Debug = false, int Line = __LINE__> constexpr int adds(const int& a, const int& b) { if (Debug) std::cout << __FUNCTION__ << " called on line " << Line << '\n'; return (a + b); } int main() { std::cout << adds(3, 7) << '\n'; std::cout << adds<true, __LINE__> (5, 9) << '\n'; return 0; } When I try to compile and build this in Debug mode Visual Studio 2017 is generating these compiler errors: 1>------ Build started: Project: Simulator,