Repository: conan-io/conan

Issue:
[bug] "conan install" detects the wrong compiler version with gcc 10 and fails
I am trying to upgrade one of my projects to use gcc 10 so I can use some C++20 features, but I ran into some issues with Conan not wanting to cooperate with the newer gcc version.

See this question for my initial findings: https://github.com/conan-io/conan/issues/6538

It turns out that even after I add "10" as a valid compiler version in "~/.conan/settings.yml" the "conan install" command still looks for the wrong version and fails saying that "1" is not a valid version.

As a temporary workaround I am able to add "1" to the list of versions in "~/.conan/settings.yml" but there's definitely something wrong going on here. Once I add "1" it works.

### Environment Details (include every applicable attribute)
  * Operating System+version: Ubuntu 19.1.0
  * Compiler+version: gcc 10.0.1
  * Conan version: 1.22.1
  * Python version: 2.7.17

### Steps to reproduce (Include if Applicable)

1. Try to use Conan with a project that uses gcc 10 as the compiler. (currently to use gcc 10 it must be built from source here https://github.com/gcc-mirror/gcc)
2. Add version "10" as a valid compiler in "~/.conan/settings.yml"
3. Attempt to do "conan install" for the project (it will fail saying version "1" is not valid)

```
ERROR: Invalid setting '1' is not a valid 'settings.compiler.version' value.
Possible values are ['10', '4.1', '4.4', '4.5', '4.6', '4.7', '4.8', '4.9', '5', '5.1', '5.2', '5.3', '5.4', '5.5', '6', '6.1', '6.2', '6.3', '6.4', '7', '7.1', '7.2', '7.3', '7.4', '8', '8.1', '8.2', '8.3', '9', '9.1', '9.2']
```

4. Add version "1" to the list (even though this seems totally wrong)
5. Try again -- "conan install" will work.


Discussion:
Gcc is still not released https://gcc.gnu.org/releases.html. We typically don't add versions to defaults settings until they are released. 

Besides adding 10 to the settings.yml, you probably need to fix the auto-detection of the default profile. Try to run:

```
$ conan profile update settings.compiler.version=10  default
```

Then try again.

Okay I'll remove "1" as a valid version in the yml file when I get home tonight and try running that command and see if that clears it up.
Interestingly enough after I got it to work once I was able to remove "1" as a valid version and it seems to keep working now... not sure why. I may need to do a fresh install of conan to reproduce the issue.
@memsharded I fully uninstalled Conan to reproduce the issue, and was able to make the error occur again.

Your suggestion to set the default compiler worked!

Still confused as to why it thought the version was "1" though until I set the default to "10"

Resolving patch:
diff --git a/conans/client/conf/detect.py b/conans/client/conf/detect.py
--- a/conans/client/conf/detect.py
+++ b/conans/client/conf/detect.py
@@ -23,7 +23,7 @@ def _gcc_compiler(output, compiler_exe="gcc"):
         if ret != 0:
             return None
         compiler = "gcc"
-        installed_version = re.search("([0-9](\.[0-9])?)", out).group()
+        installed_version = re.search("([0-9]+(\.[0-9])?)", out).group()
         # Since GCC 7.1, -dumpversion return the major version number
         # only ("7"). We must use -dumpfullversion to get the full version
         # number ("7.1.1").


Test patch:
diff --git a/conans/test/unittests/client/conf/detect/test_gcc_compiler.py b/conans/test/unittests/client/conf/detect/test_gcc_compiler.py
new file mode 100644
--- /dev/null
+++ b/conans/test/unittests/client/conf/detect/test_gcc_compiler.py
@@ -0,0 +1,19 @@
+import unittest
+
+import mock
+from parameterized import parameterized
+
+from conans.client.conf.detect import _gcc_compiler
+from conans.test.utils.tools import TestBufferConanOutput
+
+
+class GCCCompilerTestCase(unittest.TestCase):
+
+    @parameterized.expand([("10",), ("4.2",), ('7', )])
+    def test_detect_gcc_10(self, version):
+        output = TestBufferConanOutput()
+        with mock.patch("platform.system", return_value="Linux"):
+            with mock.patch("conans.client.conf.detect.detect_runner", return_value=(0, version)):
+                compiler, installed_version = _gcc_compiler(output)
+        self.assertEqual(compiler, 'gcc')
+        self.assertEqual(installed_version, version)