[Bug c++/81853] New: [C++14] "using namespace" is not a constant expression in function-like macro
t.poechtrager at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Aug 16 04:30:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81853
Bug ID: 81853
Summary: [C++14] "using namespace" is not a constant expression
in function-like macro
Product: gcc
Version: 7.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: t.poechtrager at gmail dot com
Target Milestone: ---
$ g++ --version
g++ (GCC) 7.1.1 20170630
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
---------------------------------------------------------------------------
$ cat test.cpp
namespace test {
constexpr int test_fun() { return 42; }
}
#define test_macro() \
({ \
using namespace test; \
test_fun(); \
})
int main()
{
constexpr int test_var = test_macro();
return test_var;
}
---------------------------------------------------------------------------
$ g++ test.cpp
test.cpp: In function ‘int main()’:
test.cpp:8:19: error: statement is not a constant expression
using namespace test; \
^
test.cpp:14:30: note: in expansion of macro ‘test_macro’
constexpr int test_var = test_macro();
^~~~~~~~~~
---------------------------------------------------------------------------
Clang accepts this since 3.4:
$ clang++ test.cpp -std=c++14 && ./a.out ; echo $?
42
More information about the Gcc-bugs
mailing list