在工作中,我们有一个长期运行的项目,它使用 GCC (8.2) 成功编译。当我们尝试使用基于 clang 的工具(clang-tidy、静态分析器等)时,我们发现 clang 有时会报告 GCC 接受的代码错误。这是一个最近的例子:
#include <vector>
struct Fox{};
using Foxes = std::vector<Fox>;
Foxes& foxes()
{
static Foxes f;
return f;
}
void foxy(Foxes& foxes = foxes())
{
(void)foxes;
}
Run Code Online (Sandbox Code Playgroud)
上述内容被 GCC(8.2 和 12.1)接受,并带有-Wall -Wpedantic -Wextra -Wshadow -Werror. 然而,clang却抱怨道error: default argument references parameter 'foxes'。
https://godbolt.org/z/seEb1ahKP
看起来 clang 认为标志foxes右侧的与左侧的=相同。foxesGCC 似乎认为foxes右侧的=是之前定义的函数。
当 GCC 和 clang 不一致时,通常至少其中之一是错误的(除非代码格式不正确但不需要诊断)。哪一个在这里?
GCC 的行为对我来说似乎很可疑;我本以为至少-Wshadow应该对与全局范围内定义的函数同名的参数(局部变量)发出警告。
我正在尝试构建模块。
但是这里有一些问题。
错误:内核配置无效。缺少 include/generated/autoconf.h 或 include/config/auto.conf。在内核 src 上运行“make oldconfig && make prepare”来修复它。
警告:符号版本转储 ./Module.symvers 丢失;模块将没有依赖项和 modversions。`
这是我的 makefile
ifeq ($(KERNELRELEASE),)
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
.PHONY: modules modules_install clean
else
# called from kernel build system: just declare what our modules are
obj-m := hello.o hellop.o seq.o jit.o jiq.o sleepy.o complete.o \
silly.o …Run Code Online (Sandbox Code Playgroud) #include <iostream>
class Foo { };
Foo createFoo() { return Foo(); }
void bar(Foo &&) { std::cout << "in bar(Foo &&)\n"; }
void bar(Foo const &) { std::cout << "in bar(Foo const &)\n"; }
void baz(Foo &&f) {
std::cout << "in baz, ";
bar(f);
// bar(std::move(f));
}
int main()
{
baz(createFoo());
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的预期输出是:in baz, in bar(Foo &&),但我得到了:in baz, in bar(Foo const &).如果我将调用切换到bar(请参阅注释),我会得到预期的输出,但这对我来说似乎不对.是否有一些原因编译器无法在bar(Foo &&)没有转换Foo&&为a的情况下调用Foo&&?
提前致谢!
以下是使用 ASN.1 DER 编码的证书示例
30 82 01 8F 30 81 F9 **A0** 03 02 01 02 02 01 01 30
0D 06 09 2A 86 48 86 F7 0D 01 01 05 05 00 30 0D
31 0B 30 09 06 03 55 04 03 0C 02 43 41 30 20 17
0D 31 33 30 39 31 35 31 35 33 35 30 32 5A 18 0F
32 31 31 33 30 39 32 32 31 35 33 35 …Run Code Online (Sandbox Code Playgroud)