Repository: conan-io/conan

Issue:
[feature] `check_min_cppstd` should specifically report on an unknown compiler
The `check_min_cppstd` works, or is intended to work, with default compilers. But it should handle unknown compilers that could be added by users.

Right now it doesn't handle the `None` value returned by the `deduced_cppstd` and proceeds to compare it. Should probably throw a specialized error?
https://github.com/conan-io/conan/blob/develop/conans/client/tools/settings.py#L51


Discussion:
Yes, indeed. When a compiler is not specified, it should throw an error.

About supporting different compiler, I would prefer adding them directly to Conan code base, so we can re-use for other cases.
I meant that we should let users an ability to handle that use case since it's not necessarily a hard error.
Right now it doesn't do it. `Handle` here means throwing an appropriate error which is not an InvalidConfiguration. :slightly_smiling_face: 

Resolving patch:
diff --git a/conans/client/tools/settings.py b/conans/client/tools/settings.py
--- a/conans/client/tools/settings.py
+++ b/conans/client/tools/settings.py
@@ -13,6 +13,7 @@ def check_min_cppstd(conanfile, cppstd, gnu_extensions=False):
            default from cppstd_default)
         3. If not settings.compiler is present (not declared in settings) will raise because it
            cannot compare.
+        4. If can not detect the default cppstd for settings.compiler, a exception will be raised.
 
     :param conanfile: ConanFile instance with cppstd to be compared
     :param cppstd: Minimal cppstd version required
@@ -46,7 +47,12 @@ def deduced_cppstd():
         if not compiler or not compiler_version:
             raise ConanException("Could not obtain cppstd because there is no declared "
                                  "compiler in the 'settings' field of the recipe.")
-        return cppstd_default(compiler, compiler_version)
+        cppstd = cppstd_default(compiler, compiler_version)
+        if cppstd is None:
+            raise ConanInvalidConfiguration("Could not detect the current default cppstd for "
+                                            "the compiler {}-{}.".format(compiler,
+                                                                         compiler_version))
+        return cppstd
 
     current_cppstd = deduced_cppstd()
     check_required_gnu_extension(current_cppstd)


Test patch:
diff --git a/conans/test/unittests/client/tools/cppstd_required_test.py b/conans/test/unittests/client/tools/cppstd_required_test.py
--- a/conans/test/unittests/client/tools/cppstd_required_test.py
+++ b/conans/test/unittests/client/tools/cppstd_required_test.py
@@ -90,6 +90,13 @@ def test_no_compiler_declared(self):
         self.assertEqual("Could not obtain cppstd because there is no declared compiler in the "
                          "'settings' field of the recipe.", str(raises.exception))
 
+    def test_unknown_compiler_declared(self):
+        conanfile = self._create_conanfile("sun-cc", "5.13", "Linux", None, "libstdc++")
+        with self.assertRaises(ConanInvalidConfiguration) as raises:
+            check_min_cppstd(conanfile, "14", False)
+        self.assertEqual("Could not detect the current default cppstd for "
+                         "the compiler sun-cc-5.13.", str(raises.exception))
+
 
 class ValidMinCppstdTests(unittest.TestCase):