xcode 警告:声明没有声明任何东西
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/880600/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
warning: declaration does not declare anything
提问by Stephen Petschulat
I'm getting this warning all over the place in some perfectly well functioning objective-c code within XCode. My google-fu has failed me... others have run into this but I could not find an explanation on what exactly is causing it or how it can be fixed.
我在 XCode 中一些运行良好的 Objective-c 代码中到处都收到了这个警告。我的 google-fu 使我失败了……其他人也遇到了这个问题,但我找不到关于究竟是什么原因或如何修复它的解释。
回答by Jonathan Leffler
In pure C, the following code:
在纯 C 中,以下代码:
int;
typedef int;
elicits the following warnings from GCC with no warning options set:
在没有设置警告选项的情况下从 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
Maybe you have something analogous in your code?
也许你的代码中有类似的东西?
回答by Stephen Petschulat
Found the problem and fixed it. I had this:
发现问题并修复它。我有这个:
enum eventType { singleTouch };
enum eventType type;
... and changed it to:
...并将其更改为:
enum eventType { singleTouch } type;
回答by Zac
I was able to replicate this error with the following code:
我能够使用以下代码复制此错误:
#define MY_INT int;
MY_INT a;
It compiles removing the ';' in the #define line.
它编译删除';' 在#define 行中。
回答by statueuphemism
To add another one to the list since Google brought me here: This warning can also occur with an extraneous "typename" in a using declaration:
自从 Google 将我带到这里后,将另一个添加到列表中:此警告也可能与 using 声明中无关的“typename”发生:
using SomeType = typename SomeNamespace::SomeType;
Where SomeType is not a dependent type.
其中 SomeType 不是依赖类型。
I got to this scenario after some refactoring to elevate "SomeType" outside of a templated class up to namespace scope to save on memory in an embedded C++ environment. The original implementation:
在进行了一些重构以将模板化类之外的“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
...
}
I refactored to the following, but forgot to remove the "typename" in someFunction:
我重构为以下内容,但忘记删除 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
...
}
Perhaps some other random traveler will land here and save them 15 minutes of trying to understand the warning's meaning in this context.
也许其他一些随机旅行者会在这里降落,从而节省他们 15 分钟的时间来尝试理解在这种情况下警告的含义。