# Clang now builds Postgres without additional warnings

DevFeed: [Clang now builds Postgres without additional warnings](<https://devfeed.tech/articles/clang-now-builds-postgres-without-additional-warnings-33640.md>)

Original publisher: [Read original article](<https://pgeoghegan.blogspot.com/2011/08/clang-now-builds-postgres-without.html>)

Author: Peter Geoghegan (noreply@blogger.com)

Published: 2011-08-06T20:14:00Z

Content type: opinion

Language: en

Sources: [Peter Geoghegan's blog](<https://devfeed.tech/sources/peter-geoghegan-s-blog.md>)

Topics: [clang](<https://devfeed.tech/topics/clang.md>), [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [bug](<https://devfeed.tech/topics/bug.md>), [gcc](<https://devfeed.tech/topics/gcc.md>)

Tags: [bug](<https://devfeed.tech/tags/bug.md>), [c](<https://devfeed.tech/tags/c.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [clang](<https://devfeed.tech/tags/clang.md>), [enum](<https://devfeed.tech/tags/enum.md>), [gcc](<https://devfeed.tech/tags/gcc.md>), [postgres](<https://devfeed.tech/tags/postgres.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>)

## AI overview

The article reports that Clang can build PostgreSQL without additional warnings beyond one warning also produced by GCC. It describes how Clang's diagnostic context helped reveal a potentially dangerous enum-type misuse in PostgreSQL code and notes fixes for other spurious warnings.

## Source excerpt

I'm happy to report that as of this evening, Clang builds PostgreSQL without any warnings, apart from a single remaining warning that also occurs when building with GCC, which is actually a bug in GNU Flex that the Flex developers don't seem to want to fix. On GCC 4.6, the warning looks like this: In file included from gram.y:12962:0: scan.c: In function 'yy_try_NUL_trans': scan.c:16246:23: warning: unused variable 'yyg' [-Wunused-variable] With Clang, however, it looks like this: scan.c:16246:23: warning: unused variable 'yyg' [-Wunused-variable] struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */ ^ Note that the "^" is directly underneath the offending variable "yyg" on the terminal emulator that generated this warning. Note also that Clang usefully gives the context of the warning, and as a result a comment is displayed that suggests that the warning is spurious. The Clang developers finally committed a fix to remove spurious warnings that occured when building Postgres as a result of it being statically detected that there are assignments past what appears to be the end of a single element array at the end of a struct. That doesn't happen now, although only under circumstances exactly consistent with the use of a popular idiom that is seen quite a bit in the Postgres code. In working towards removing all Clang warnings, we detected a bug; we were assigning an enum constant from one enum to a variable that was actually another type of enum, which represented a potentially dangerous misuse of an abstraction that the Postgres code uses to represent nodes. This all occurred within a nested macro. Without Clang, it probably would have taken a long time for the problem to be noticed.