This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/81853] New: [C++14] "using namespace" is not a constant expression in function-like macro
- From: "t.poechtrager at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 15 Aug 2017 21:15:33 +0000
- Subject: [Bug c++/81853] New: [C++14] "using namespace" is not a constant expression in function-like macro
- Auto-submitted: auto-generated
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