【发布时间】:2009-05-19 01:31:40
【问题描述】:
我在 XCode 中一些运行良好的 Objective-c 代码中到处都收到了这个警告。我的 google-fu 让我失望了……其他人也遇到过这种情况,但我找不到关于究竟是什么原因导致它或如何修复它的解释。
【问题讨论】:
-
也许您应该提供一些引发警告的示例代码。
标签: c++ iphone objective-c xcode
我在 XCode 中一些运行良好的 Objective-c 代码中到处都收到了这个警告。我的 google-fu 让我失望了……其他人也遇到过这种情况,但我找不到关于究竟是什么原因导致它或如何修复它的解释。
【问题讨论】:
标签: c++ iphone objective-c xcode
纯C语言,如下代码:
int;
typedef int;
在未设置警告选项的情况下从 GCC 引发以下警告:
x.c:1: warning: useless keyword or type name in empty declaration
x.c:1: warning: empty declaration
x.c:2: warning: useless keyword or type name in empty declaration
x.c:2: warning: empty declaration
也许你的代码中有类似的东西?
【讨论】:
发现问题并解决。我有这个:
enum eventType { singleTouch };
enum eventType type;
...并将其更改为:
enum eventType { singleTouch } type;
【讨论】:
我能够使用以下代码复制此错误:
#define MY_INT int;
MY_INT a;
它编译删除';'在#define 行中。
【讨论】:
在 Google 将我带到这里后添加另一个到列表中:此警告也可能在 using 声明中与无关的“类型名”一起出现:
using SomeType = typename SomeNamespace::SomeType;
SomeType 不是依赖类型。
经过一些重构以将模板类之外的“SomeType”提升到命名空间范围以节省嵌入式 C++ 环境中的内存后,我遇到了这种情况。原始实现:
namespace SomeNamespace {
template <typename T>
SomeClass
{
public:
enum class SomeType
{
A,
B,
};
...
};
} //namespace SomeNamespace
...
void someFunction()
{
using SomeType = typename SomeNameSpace::SomeClass<uint8_t>::SomeType;
//typename is required above to resolve dependent scope
...
}
我重构为以下内容,但忘记删除 someFunction 中的“typename”:
namespace SomeNamespace {
// Now elevated to namespace scope so it is clear to the compiler that it does
// not need to be created for every template type of the class. While most
// compilers may be able to figure this one out easily, mine couldn't based
// on the optimization settings I need to use for my embedded project.
enum class SomeType
{
A,
B,
};
template <typename T>
SomeClass
{
public:
...
};
} //namespace SomeNamespace
...
void someFunction()
{
using SomeType = **typename** SomeNameSpace::SomeType;
//typename is no longer needed, but its removal was missed during refactoring
...
}
也许其他一些随机的旅行者会在这里降落,并为他们节省 15 分钟的时间来尝试理解警告在此上下文中的含义。
【讨论】: