我对gcc 5.1.0有一个奇怪的问题。以下最小代码
#!/usr/bin/env phantomjs
function waitFor(testFx, onReady, timeOutMillis) {
var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 5000, //< Default Max Timout is 5s
start = new Date().getTime(),
condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()), //< defensive code
interval = setInterval(function() {
if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) {
// If not time-out yet and condition not yet fulfilled
condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()); //< defensive code
} else {
if(!condition) {
// If condition still not fulfilled (timeout but condition is 'false')
console.log("'waitFor()' timeout");
phantom.exit(1);
} else {
// Condition fulfilled (timeout and/or condition is 'true')
console.log("'waitFor()' finished in " + (new Date().getTime() - start) + "ms.");
typeof(onReady) === "string" ? eval(onReady) : onReady(); //< Do what it's supposed to do once the condition is fulfilled
clearInterval(interval); //< Stop this interval
}
}
}, 500); //repeat check every 500ms
};
var system = require('system')
var width = window.parseInt(system.args[1])
var height = window.parseInt(system.args[2])
var url = system.args[3]
var relative_path = system.args[4]
var page = require('webpage').create();
var resources = [];
page.onResourceRequested = function(request) {
resources[request.id] = request.stage;
};
page.onResourceReceived = function(response) {
resources[response.id] = response.stage;
};
page.onResourceError = function(resourceError) {
page.reason = resourceError.errorString;
page.reason_url = resourceError.url;
};
//Loading whole webpage
page.viewportSize = {
width: 2000,
height: 10000
};
page.open(url, function(status) {
if (status !== 'success') {
console.log("Error opening url \"" + page.reason_url + "\": " + page.reason );
} else {
waitFor(function() {
page.viewportSize = { width: width, height: height };
page.render(relative_path);
}, 10000);
}
phantom.exit();
});
导致编译器错误
// header 1
namespace A {
template<typename X>
inline constexpr X square(X x) { return x*x; }
}
// header 2
namespace A { namespace B {
template<typename X>
struct matrix { X A[3][3]; };
template<typename X>
matrix<X> square(matrix<X> const&) noexcept;
} }
// source, includes both headers
namespace A { namespace B {
using A::square; // no problem without this line
template<typename X>
matrix<X> square(matrix<X> const&M) noexcept
{
matrix<X> R;
for(int i=0; i!=3; ++i)
for(int j=0; j!=3; ++j)
R.A[i][j] = M.A[i][0]*M.A[0][j] +
M.A[i][1]*M.A[1][j] +
M.A[i][2]*M.A[2][j] ;
return R;
}
template matrix<double> square(matrix<double> const&) noexcept;
} }
如果删除了源中指示的行,则错误消失。代码用clang ++编译好,但gcc 4.8也显示错误。我试图在gcc bugzilla找到相关的错误报告但没有成功,但这可能没有任何意义。所以我的主要问题是:这确实是一个gcc bug,如果是的话,它是新的吗?
这可能与古代bug 37374有关,它显示了没有模板的相似行为。我已经提交了一份新的bug report。