From 4e6c80197f1cc46dfdef0300de46847c7cfbdcb0 Mon Sep 17 00:00:00 2001
From: Matthew Pickering <matthewtpickering@gmail.com>
Date: Wed, 16 Feb 2022 10:40:55 +0000
Subject: [PATCH] Always define __GLASGOW_HASKELL_PATCHLEVEL1/2__ macros

As #21076 reports if you are using `-Wcpp-undef` then you get warnings
when using the `MIN_VERSION_GLASGOW_HASKELL` macro because
__GLASGOW_HASKELL_PATCHLEVEL2__ is very rarely explicitliy set (as
version numbers are not 4 components long).

This macro was introduced in 3549c952b535803270872adaf87262f2df0295a4
and it seems the bug has existed ever since.

Fixes #21076
---
 m4/fp_setup_project_version.m4         | 4 ++++
 testsuite/tests/driver/all.T           | 1 +
 testsuite/tests/driver/patch-level2.hs | 6 ++++++
 3 files changed, 11 insertions(+)
 create mode 100644 testsuite/tests/driver/patch-level2.hs

diff --git a/m4/fp_setup_project_version.m4 b/m4/fp_setup_project_version.m4
index 26df01865b1b..d51759add71a 100644
--- a/m4/fp_setup_project_version.m4
+++ b/m4/fp_setup_project_version.m4
@@ -77,6 +77,10 @@ AC_DEFUN([FP_SETUP_PROJECT_VERSION],
     ProjectPatchLevel1=`echo $ProjectPatchLevel | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\1/'`
     ProjectPatchLevel2=`echo $ProjectPatchLevel | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\3/'`
 
+    # The project patchlevel1/2 is zero unless stated otherwise
+    test -z "$ProjectPatchLevel1" && ProjectPatchLevel1=0
+    test -z "$ProjectPatchLevel2" && ProjectPatchLevel2=0
+
     AC_SUBST([ProjectPatchLevel1])
     AC_SUBST([ProjectPatchLevel2])
 
diff --git a/testsuite/tests/driver/all.T b/testsuite/tests/driver/all.T
index 907002fcf709..af81d61eb86b 100644
--- a/testsuite/tests/driver/all.T
+++ b/testsuite/tests/driver/all.T
@@ -303,3 +303,4 @@ test('T20200loop', extra_files(['T20200loop']), multimod_compile,
      ['Datatypes', '-iT20200loop -O -v0'])
 test('T20316', normal, makefile_test, [])
 test('MultiRootsErr', normal, multimod_compile_fail, ['MultiRootsErr', 'MultiRootsErr'])
+test('patch-level2', normal, compile, ['-Wcpp-undef'])
diff --git a/testsuite/tests/driver/patch-level2.hs b/testsuite/tests/driver/patch-level2.hs
new file mode 100644
index 000000000000..ae89fbed8ed8
--- /dev/null
+++ b/testsuite/tests/driver/patch-level2.hs
@@ -0,0 +1,6 @@
+{-# LANGUAGE CPP #-}
+module PatchLevel2 where
+
+
+p2 = __GLASGOW_HASKELL_PATCHLEVEL2__
+p1 = __GLASGOW_HASKELL_PATCHLEVEL1__
-- 
GitLab