[bug] Fix MacOS compilation and implicit conversion in to_qasm()#229
[bug] Fix MacOS compilation and implicit conversion in to_qasm()#229xumingkuan merged 4 commits intomasterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses compilation issues related to C++17 standard compliance and macOS SDK configuration. The changes ensure the codebase compiles correctly by explicitly setting the C++17 standard flag and adding macOS-specific SDK paths. Additionally, string literals passed to the to_qasm function are wrapped with std::string() constructors, though this appears unnecessary given the function signature accepts const std::string&.
Key changes:
- Explicitly added
-std=c++17flag to CMAKE_CXX_FLAGS for non-MSVC builds - Added macOS SDK path configuration using
xcrunandisysrootflags - Wrapped string literal arguments to
Graph::to_qasm()calls with explicitstd::string()constructors in test files
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| CMakeLists.txt | Added -std=c++17 flag and macOS SDK path configuration for compilation |
| src/test/test_rigetti_td_disabled.cpp | Wrapped string literal in std::string() constructor for to_qasm() call |
| src/test/test_graph_to_qasm.cpp | Wrapped string literal in std::string() constructor for to_qasm() call |
| src/test/test_from_and_to_qasm.cpp | Wrapped string literal in std::string() constructor for to_qasm() call |
| src/test/test_apply_xfer.cpp | Wrapped string literal in std::string() constructor for to_qasm() call |
| .gitignore | Added .cache/ directory to gitignore |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| Graph graph(&ctx, dag); | ||
| graph.to_qasm("temp.qasm", /*print_result=*/true, true); | ||
| graph.to_qasm(std::string("temp.qasm"), /*print_result=*/true, true); |
There was a problem hiding this comment.
The std::string() wrapper on line 20 is inconsistent with line 21 where draw_circuit (which also accepts const std::string& parameters) is called with string literals directly. Since to_qasm accepts const std::string&, the explicit wrapper is unnecessary - string literals implicitly convert to std::string. Consider removing the wrapper for consistency: graph.to_qasm("temp.qasm", /*print_result=*/true, true);
| graph.to_qasm(std::string("temp.qasm"), /*print_result=*/true, true); | |
| graph.to_qasm("temp.qasm", /*print_result=*/true, true); |
| true); | ||
| graph_after_h_cz_merge->to_qasm( | ||
| "circuit/voqc-benchmarks/after_h_cz_merge.qasm", false, false); | ||
| std::string("circuit/voqc-benchmarks/after_h_cz_merge.qasm"), false, |
There was a problem hiding this comment.
The std::string() wrapper is inconsistent with line 114 in the same file where to_qasm(output_fn, false, false) is called without wrapping. Since the function signature is void to_qasm(const std::string &save_filename, bool print_result, bool print_guid), string literals implicitly convert to const std::string&. Consider removing the wrapper for consistency: graph_after_h_cz_merge->to_qasm("circuit/voqc-benchmarks/after_h_cz_merge.qasm", false, false);
| std::string("circuit/voqc-benchmarks/after_h_cz_merge.qasm"), false, | |
| "circuit/voqc-benchmarks/after_h_cz_merge.qasm", false, |
| auto graph = | ||
| Graph::from_qasm_file(&ctx, "../experiment/nam_rm_circs/gf2^6_mult.qasm"); | ||
| graph->to_qasm("test.qasm", false, false); | ||
| graph->to_qasm(std::string("test.qasm"), false, false); |
There was a problem hiding this comment.
The std::string() wrapper is unnecessary since to_qasm accepts const std::string& which allows implicit conversion from string literals. This is inconsistent with other test files like test_rotation_merging.cpp and test_toffoli_flip.cpp where variables of type std::string are passed directly. Consider using the literal directly: graph->to_qasm("test.qasm", false, false);
| graph->to_qasm(std::string("test.qasm"), false, false); | |
| graph->to_qasm("test.qasm", false, false); |
| } | ||
|
|
||
| best_graph->to_qasm("test.qasm", false, false); | ||
| best_graph->to_qasm(std::string("test.qasm"), false, false); |
There was a problem hiding this comment.
The std::string() wrapper is unnecessary since to_qasm accepts const std::string& which allows implicit conversion from string literals. This is inconsistent with similar calls in other test files. Consider using the literal directly: best_graph->to_qasm("test.qasm", false, false);
| best_graph->to_qasm(std::string("test.qasm"), false, false); | |
| best_graph->to_qasm("test.qasm", false, false); |
No description provided.