Wal*_*ter 13 c++ templates using-directives constexpr c++11
对于以下代码
#include <array>
template<unsigned MaxP, typename type>
struct kernel
{
static constexpr unsigned max_pole(unsigned P)
{ return P>MaxP? MaxP:P; }
template<unsigned P>
using array = std::array<type,max_pole(P)>; // wrong?
template<unsigned P>
static void do_something(array<P> const&, array<P>&);
};
Run Code Online (Sandbox Code Playgroud)
gcc 4.7.0(g ++ -c -std = c ++ 11)给出
error: ‘max_pole’ was not declared in this scope
Run Code Online (Sandbox Code Playgroud)
这是正确的(编译器的行为)吗?请注意,如果我max_pole通过kernel::max_pole在指定的行上替换它来解决它,它编译得很好.
编辑报告给bugzilla,接受为bug c ++/55992,请参阅http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55992.gcc 4.7.x和4.8.0也会出现这种情况.
使用Clang 3.2可以很好地编译模板.我坚信这是一个GCC错误(也存在于GCC 4.7.2中,顺便说一句).GCC 4.8.0的更改说明似乎没有提到任何此类错误修复.
另请注意,如果删除声明,编译错误就会消失do_something<>,这应该没有任何区别.
还有一个提示:虽然这个模板不能在GCC 4.7.2上编译:
template<unsigned MaxP, typename type>
struct kernel
{
static constexpr unsigned max_pole(unsigned P)
{ return P>MaxP? MaxP:P; }
template<typename T>
using array2 = int[max_pole(3)]; // ERROR!
static void do_something(array2<int> const&, array2<int>&);
};
Run Code Online (Sandbox Code Playgroud)
这个模板确实编译:
template<unsigned MaxP, typename type>
struct kernel
{
static constexpr unsigned max_pole(unsigned P)
{ return P>MaxP? MaxP:P; }
// template<typename T> <--- removed
using array2 = int[max_pole(3)]; // OK
static void do_something(array2 const&, array2&);
};
Run Code Online (Sandbox Code Playgroud)
由于max_pole是在两种情况下的无保留意见的独立名称,查找策略应该是在这两种情况下是相同的,而事实并非如此.对我来说,这可以将其视为一个错误.
| 归档时间: |
|
| 查看次数: |
3884 次 |
| 最近记录: |