尝试使用clang和GCC进行C ++版本98、04、11、17、20(部分)的编译。
test.hpp
namespace test {
struct test_struct {};
void test_function(const test_struct& x);
}
test.cpp
#include "test.hpp"
void test::test_function(const test::test_struct& x) { }
main.cpp
#include "test.hpp"
#include <iostream>
int main() {
test::test_struct x;
std::cout << test_function(x) << std::endl;
}
我希望它会报告一个错误,指出在test_function
中被调用时未声明main
。
但是,它可以编译并正常运行。此外,当更改test_function
使其使用int
而不是struct
时,确实会报告错误。