Clang 15 will be available with Red Hat Enterprise Linux (RHEL) 8.8 and RHEL 9.2. It comes with some new and upgraded warnings that will help modernize your C/C++ code base. Starting with version 15, Clang is beginning to emit more warnings and errors by default for code constructs that have been deprecated in newer versions of C. This includes implicit function definitions and functions without prototypes.
-Wint-conversion
In Clang 15, the -Wint-conversion warning has been upgraded to an error. This warning catches when an integer is being implicitly converted to a pointer. One common mistake that this warning will catch is implicit function definitions, where code tries to call a function that has not been declared. In C89/C90, undeclared functions are assumed to return int, so if you try to assign the value of an undeclared function to a pointer, Clang will now emit this error:
$ cat int-conversion.c int foo () { char *s = missing_decl(); } $ clang -c int-conversion.c int-conversion.c:2:13: warning: call to undeclared function 'missing_decl'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] char *s = missing_decl(); ^ int-conversion.c:2:9: error: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion] char *s = missing_decl(); ^ ~~~~~~~~~~~~~~ 1 warning and 1 error generated.
-Wdeprecated-non-prototype
-Wdeprecated-non-prototype is a new warning that will catch cases where a deprecated prototype would have a different behavior in C2x.
cat deprecated-non-prototype.c static void f(); static void f(char *s) { } [root@intel-xeon-ee-iotg-04 ~]# clang -c deprecated-non-prototype.c deprecated-non-prototype.c:1:13: warning: a function declaration without a prototype is deprecated in all versions of C and is treated as a zero-parameter prototype in C2x, conflicting with a subsequent definition [-Wdeprecated-non-prototype] static void f(); ^ deprecated-non-prototype.c:3:13: note: conflicting prototype is here static void f(char *s) { } ^ 1 warning generated.
Definition without a prototype
Clang 15 will now emit an error if you forget the prototype in a function definition that has a declaration with a prototype.
cat prototype.c void f(int); void f() {} clang -c prototype.c prototype.c:1:19: error: conflicting types for 'f' void f(int); void f() {} ^ prototype.c:1:6: note: previous declaration is here void f(int); void f() {} ^ 1 error generated.
-Wunused-but-set-variable improvements
The -Wunused-but-set-variable warning, which checks for unused variables in the code, has been updated to be able to detect variables for unary operators like ++.
$ cat unused-but-set.c void do_something(void); void f(void) { int count, i; count = 0; for (i = 0; i < 5; i++) { do_something(); count++; } } $ clang -c unused-but-set.c -Wunused-but-set-variable unused-but-set.c:5:6: warning: variable 'count' set but not used [-Wunused-but-set-variable] int count, i; ^ 1 warning generated.
Learn more
While Clang 15 won’t be available in RHEL until the forthcoming minor releases are out, you can get a preview of the latest Clang 15 builds from CentOS Stream. Even if you are using Gnu Compiler Collection (GCC), or an older version of Clang as the compiler for your application, you can still do a one-off build with Clang 15 to see these new warnings and errors to catch any existing mistakes in your code. Clang 16 and future versions of GCC will become even more strict about deprecated C constructs, so it’s a good idea to start finding these problems as soon as you can.
저자 소개
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
오리지널 쇼
엔터프라이즈 기술 분야의 제작자와 리더가 전하는 흥미로운 스토리
제품
- Red Hat Enterprise Linux
- Red Hat OpenShift Enterprise
- Red Hat Ansible Automation Platform
- 클라우드 서비스
- 모든 제품 보기
툴
체험, 구매 & 영업
커뮤니케이션
Red Hat 소개
Red Hat은 Linux, 클라우드, 컨테이너, 쿠버네티스 등을 포함한 글로벌 엔터프라이즈 오픈소스 솔루션 공급업체입니다. Red Hat은 코어 데이터센터에서 네트워크 엣지에 이르기까지 다양한 플랫폼과 환경에서 기업의 업무 편의성을 높여 주는 강화된 기능의 솔루션을 제공합니다.