0

I'm trying to use std::regex to validate some variables from a file in my c++11 project.

For now I need to validate if a string is a valid URL or not. Here is my code: https://godbolt.org/z/4Pn9eYEce

As you see, it works as expected. It returns a true.

However, when I run the same code on my server, it returns a false.

enter image description here

I really don't know why.

My server is Ubuntu 16.04.4 LTS, and the version of GCC is 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.11).

Yves
  • 11,597
  • 17
  • 83
  • 180
  • 1
    [Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/q/285551/995714) – phuclv Sep 15 '21 at 04:16
  • the question must be self-contained with all the texts and necessary code so that it doesn't become invalid when external links rot. Besides Ubuntu 16.04 is out of its lifetime and is unsupported here or [ubuntu.se] – phuclv Sep 15 '21 at 04:21

1 Answers1

0

Must be a compiler thing, compiling on gcc5.4 with -Wformat -std=c++17, and then running it also returns 0.

https://godbolt.org/z/a8o9x9nWP

Probably best if you update your compiler to a newer version.

Pepijn Kramer
  • 9,356
  • 2
  • 8
  • 19
  • But I have no right to upgrade my compiler... Well, maybe I have to abandon this kind of validation for now... – Yves Sep 15 '21 at 03:59
  • 2
    Read this : https://stackoverflow.com/questions/12530406/is-gcc-4-8-or-earlier-buggy-about-regular-expressions. Seems they didn't get it right in 5.4 either. Can you get the compiler updated for you then? I know I would start asking around to fix the real problem ;) Don't give up so easily. – Pepijn Kramer Sep 15 '21 at 04:05
  • This link helps, at least I can control the return value based on the version of my GCC... For now I would tell my team this issue but the leader may decide to upgrade the compiler in maybe 2 or 3 years... lol. – Yves Sep 15 '21 at 04:10
  • Run a testbuild on a test system with the new compiler installed and then run the unit/integration tests. This will indicate how risky it is before upgrading. – Pepijn Kramer Sep 15 '21 at 04:32