pw_status: Workaround for macro-constant collision

pw_status/status.h uses constants named like macros (e.g. OK and
INTERNAL). Have the status.h header undefine any such macros so that it
can compile successfully. Projects that rely on macros with these names
and status in the same translation unit should rename the macros or
include the macro definitions after status.h.

Change-Id: I37d270e10febc9a8a28fd026c2181e097e6236f7
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/18880
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
diff --git a/pw_status/public/pw_status/status.h b/pw_status/public/pw_status/status.h
index fc1063d..5135841 100644
--- a/pw_status/public/pw_status/status.h
+++ b/pw_status/public/pw_status/status.h
@@ -159,6 +159,35 @@
 
 }  // extern "C"
 
+// This header violates the Pigweed style guide! It declares constants that use
+// macro naming style, rather than constant naming style (kConstant). This is
+// done for readability and for consistency with Google's standard status codes
+// (e.g. as in gRPC).
+//
+// The problem is that the status code names might overlap with macro
+// definitions. To workaround this, this header undefines any macros with these
+// names.
+//
+// If your project relies on a macro with one of these names (e.g. INTERNAL),
+// make sure it is included after status.h so that the macro is defined.
+#undef OK
+#undef CANCELLED
+#undef UNKNOWN
+#undef INVALID_ARGUMENT
+#undef DEADLINE_EXCEEDED
+#undef NOT_FOUND
+#undef ALREADY_EXISTS
+#undef PERMISSION_DENIED
+#undef UNAUTHENTICATED
+#undef RESOURCE_EXHAUSTED
+#undef FAILED_PRECONDITION
+#undef ABORTED
+#undef OUT_OF_RANGE
+#undef UNIMPLEMENTED
+#undef INTERNAL
+#undef UNAVAILABLE
+#undef DATA_LOSS
+
 namespace pw {
 
 // The Status class is a thin, zero-cost abstraction around the pw_Status enum.
diff --git a/pw_status/status_test.cc b/pw_status/status_test.cc
index 98afa56..c18f561 100644
--- a/pw_status/status_test.cc
+++ b/pw_status/status_test.cc
@@ -12,6 +12,25 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
+// Make sure status works if these macros are defined.
+#define OK Uh oh, this macro is defined !
+#define CANCELLED Uh oh, this macro is defined !
+#define UNKNOWN Uh oh, this macro is defined !
+#define INVALID_ARGUMENT Uh oh, this macro is defined !
+#define DEADLINE_EXCEEDED Uh oh, this macro is defined !
+#define NOT_FOUND Uh oh, this macro is defined !
+#define ALREADY_EXISTS Uh oh, this macro is defined !
+#define PERMISSION_DENIED Uh oh, this macro is defined !
+#define UNAUTHENTICATED Uh oh, this macro is defined !
+#define RESOURCE_EXHAUSTED Uh oh, this macro is defined !
+#define FAILED_PRECONDITION Uh oh, this macro is defined !
+#define ABORTED Uh oh, this macro is defined !
+#define OUT_OF_RANGE Uh oh, this macro is defined !
+#define UNIMPLEMENTED Uh oh, this macro is defined !
+#define INTERNAL Uh oh, this macro is defined !
+#define UNAVAILABLE Uh oh, this macro is defined !
+#define DATA_LOSS Uh oh, this macro is defined !
+
 #include "pw_status/status.h"
 
 #include "gtest/gtest.h"