Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is the tranformed code in https://cppinsights.io identical with the one transformed by my local compiler clang-1200.0.32.29 #424

Closed
declmal opened this issue Nov 14, 2021 · 2 comments

Comments

@declmal
Copy link

declmal commented Nov 14, 2021

In view of my lack of knowledge on features of different compiler versions.
I submit my source code (max1.cc as follows) on https://cppinsights.io/

#include <cstdio>

template<typename T1, typename T2>
auto max(T1 a, T2 b) {
	return b < a ? a : b;
}

int main() {
    int a = 1;
    float b = 2.2;
    auto x = max<int, float>(a, b);
}

and the transformed Insignt shows:

#include <cstdio>

template<typename T1, typename T2>
auto max(T1 a, T2 b) {
	return b < a ? a : b;
}

#ifdef INSIGHTS_USE_TEMPLATE
template<>
float max<int, float>(int a, float b)
{
  return b < static_cast<float>(a) ? static_cast<float>(a) : b;
}
#endif


int main()
{
  int a = 1;
  float b = static_cast<float>(2.2000000000000002);
  float x = max<int, float>(a, b);
}

But I wonder whether this transformation is identical with the one that my local compiler does.
As mentioned in the compatibility part of README.md, the most recent stable version of clang is supported.
So, will the transformaton process influenced by the version of clang?

PS. My clang version on macos

$ /usr/bin/clang --version
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin20.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

PSS. My CMakeLists.txt

cmake_minimum_required(VERSION 3.18)
set(CMAKE_C_COMPILER /usr/bin/clang)
set(CMAKE_CXX_COMPILER /usr/bin/clang++)
set(CMAKE_CXX_STANDARD 14)
project(tmp)
add_executable(max1 src/max1.cc)
@declmal declmal changed the title Is the tranformed code identical with my local actual Is the tranformed code in cppinsights.io identical with the one transformed by my local compiler Nov 14, 2021
@declmal declmal changed the title Is the tranformed code in cppinsights.io identical with the one transformed by my local compiler Is the tranformed code in https://cppinsights.io identical with the one transformed by my local compiler Nov 14, 2021
@declmal declmal changed the title Is the tranformed code in https://cppinsights.io identical with the one transformed by my local compiler Is the tranformed code in https://cppinsights.io identical with the one transformed by my local compiler clang-1200.0.32.29 Nov 14, 2021
@andreasfertig
Copy link
Owner

Hello @declmal,

well that is a very good question. The result depends on various factors. The Clang version is one, the operating system the other, and the standard library.

The webserver runs on Linux. C++ Insights there uses libstdc++ (GCC's STL) as a default. The code that you show here, I assume, is identical. To be sure, you have to run C++ Insights locally with the exact same version of Clang.

Is there any particular reason why you want to be sure?

Andreas

@declmal
Copy link
Author

declmal commented Nov 15, 2021

Hello @andreasfertig
Thanks for your answer.
I am currently building c++ projects with template programming.
If both results are identical or almost the same, I could use insignts to debug my project (with tedious compilation erros...), since the transformed code would be informative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants