Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k1f2z-0005We-0o for pgsql-interfaces@arkaria.postgresql.org; Sat, 01 Aug 2020 00:06:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k1f2w-0005QR-4q for pgsql-interfaces@arkaria.postgresql.org; Sat, 01 Aug 2020 00:06:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k1f2v-0005QK-VO for pgsql-interfaces@lists.postgresql.org; Sat, 01 Aug 2020 00:06:41 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k1f2o-0005gp-OQ for pgsql-interfaces@postgresql.org; Sat, 01 Aug 2020 00:06:41 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 07106VIb1853328; Fri, 31 Jul 2020 20:06:31 -0400 From: Tom Lane To: Ashutosh Sharma cc: pgsql-interfaces@postgresql.org Subject: Re: ecpg: issue related to preprocessor directives In-reply-to: References: Comments: In-reply-to Ashutosh Sharma message dated "Fri, 31 Jul 2020 10:46:00 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1853326.1596240391.1@sss.pgh.pa.us> Date: Fri, 31 Jul 2020 20:06:31 -0400 Message-ID: <1853327.1596240391@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Ashutosh Sharma writes: > When the following ecpg program having preprocessor directives is compiled, > the output produced is not correct. > ... > As seen from above output, both exec sql ifdef and exec sql else block got > compiled which is wrong. If the above output is further compiled using gcc > compiler, the compilation would fail. Looking at pgc.l, it seems that 'elif' is treated as though it were 'endif' followed by 'ifdef', which of course completely loses the expected property that a previous successful branch would keep the elif branch from being expanded. While this doesn't look terribly hard to fix, I'm a little disturbed by the fact that the existing semantics seem to date back to 1999 (b57b0e044). We're probably risking breaking existing app code if we change it. I think we *should* change it, of course, but I'm kind of inclined not to back-patch. regards, tom lane