]> granicus.if.org Git - postgresql/commitdiff
Add a note to PG_TRY's documentation about volatile safety.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 26 Jan 2015 20:53:37 +0000 (15:53 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 26 Jan 2015 20:53:37 +0000 (15:53 -0500)
We had better memorialize what the actual requirements are for this.

src/include/utils/elog.h

index fe5dec03a7acd3403fe64cb9620bb3b4ac652c9f..b5cfc9cbc88f141a55c0276fa1661b8ed6b6bfc2 100644 (file)
@@ -332,6 +332,13 @@ extern PGDLLIMPORT ErrorContextCallback *error_context_stack;
  * not without taking thought for what will happen during ereport(FATAL).
  * The PG_ENSURE_ERROR_CLEANUP macros provided by storage/ipc.h may be
  * helpful in such cases.
+ *
+ * Note: if a local variable of the function containing PG_TRY is modified
+ * in the PG_TRY section and used in the PG_CATCH section, that variable
+ * must be declared "volatile" for POSIX compliance.  This is not mere
+ * pedantry; we have seen bugs from compilers improperly optimizing code
+ * away when such a variable was not marked.  Beware that gcc's -Wclobbered
+ * warnings are just about entirely useless for catching such oversights.
  *----------
  */
 #define PG_TRY()  \