使用其他类型的函数声明违反 C++ 中的类型安全?

Violation of type safety in C++ with function declaration of other type?

我是 C++ 的新手,只是尝试一些东西。我坚持使用以下代码:

#include<iostream>  

void t(){
    std::cout << "func t()" << std::endl;
}

int main(int argc, char **argv) {
    int t(); //declaration of function
    std::cout << t() << std::endl;
}

输出为"func t()\n6295712"。我关心的是 t() 打印的随机数(?)。

我的问题是:为什么允许声明另一个 return 类型的函数(此处:int 而不是 void)而不会出现任何错误?这不是违反类型安全因为我从来没有用 return 类型 "int" 定义函数吗?

使用的编译器:gcc (Ubuntu 4.8.4-2ubuntu1~14.04.1) 4.8.4

我能找到的唯一相关内容是 [basic.scope.pdecl] 中的注释:

Function declarations at block scope and variable declarations with the extern specifier at block scope refer to declarations that are members of an enclosing namespace, but they do not introduce new names into that scope.

所以当你写的时候:

void t();

int main() {
    int t();  // *
}

该内部声明引用了封闭命名空间的成员。所以相当于写了:

void t();
int t();

int main() {}

但是函数不能仅在 return 类型中重载,所以这段代码格式错误。 Clang 拒绝这两个程序,gcc 只拒绝后者。我相信这是一个 gcc 错误。