在大型代码库中,我想查找对某组函数的所有调用。 Clang的deprecated
和unavailable
属性并不完全符合我的要求,至少从Apple LLVM-6.0版本开始。例如:
__attribute__((deprecated)) void A();
__attribute__((deprecated)) void B();
void C();
void A()
{
B();
}
void B()
{
A();
}
void C()
{
A();
B();
}
编译器会发出有关从C调用A和B的警告,但不会调用A到B的调用,反之亦然。
有许多问题存在问题,因此逐一评论声明似乎不切实际。
答案 0 :(得分:1)
我认为不在A()
内拨打B()
以及从B()
内拨打A()
的警告的原因是这些呼叫在机构内已弃用的功能。由于函数本身已被弃用,因此在报告这些函数中的弃用调用时没有太多优点;省略这些错误可以避免一些“误报”。当您消除已弃用的函数时,它们内部的调用就不会出现问题。
我使用XCode 6.4编译了一个经过温和修改的代码版本 - 正在运行gcc --version
:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.4.0
Thread model: posix
代码unavailable.c
:
__attribute__((deprecated)) void A(void);
__attribute__((deprecated)) void B(void);
void C(void);
void A(void)
{
B();
}
void B(void)
{
A();
}
void C(void)
{
A();
B();
}
汇编:
$ make unavailable.o
gcc -O3 -g -Wall -Wextra -Werror -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition -c unavailable.c
unavailable.c:17:5: error: 'A' is deprecated [-Werror,-Wdeprecated-declarations]
A();
^
unavailable.c:5:6: note: 'A' has been explicitly marked deprecated here
void A(void)
^
unavailable.c:18:5: error: 'B' is deprecated [-Werror,-Wdeprecated-declarations]
B();
^
unavailable.c:10:6: note: 'B' has been explicitly marked deprecated here
void B(void)
^
2 errors generated.
rmk: error code 1
$
我必须将void
参数添加到C函数中,因为在C中,声明为void C();
的函数没有原型 - C
是一个未指定的函数(但不是可变参数) )参数列表并且不返回任何值。 ('not variadic'位意味着它在参数列表的末尾没有省略号...
。在调用这样的函数之前,你必须总是在范围内有一个原型。)
答案 1 :(得分:0)
我最后写了一个小程序来搜索__attribute__((unavailable))
技巧遗漏的电话。