Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Compilation issue with custom state type with clang only

Đang mở
#48 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
cpp
Lĩnh vực
compilers

Hướng nghiên cứu

Bắt đầu với reproducer Godbolt được liên kết và so sánh clang++ với các trình biên dịch chấp nhận nó. Kiểm tra đường dẫn include của boost/numeric/odeint.hpp và việc sử dụng vector_space_algebra với std::pair; hoàn tất nghĩa là chương trình được hiển thị biên dịch được bằng clang++ mà không di chuyển các định nghĩa toán tử lên trước include odeint.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

In the code below, I am working with a custom state-type (a std::pair in this case). The code compiles with g++, icc, msvc. With clang however, compilation fails. In order to get it to build successfully, I apparently need to define operator+() and operator*() for the state type before including the odeint header. Link to godbolt: https://godbolt.org/z/6eavzdxbf

#include <cstdlib>
#include <utility>

#include <boost/numeric/odeint.hpp> // if included here, compilations fails with clang++

using state_type = std::pair<double, double>;
using deriv_type = state_type;
using time_type = double;

state_type operator+(state_type a, state_type const& b);
state_type operator*(state_type a, time_type b);
state_type operator*(time_type b, state_type a);

//~ #include <boost/numeric/odeint.hpp> // if included here, no error!

state_type operator+(state_type a, state_type const& b) {
	a.first += b.first;
	a.second += b.second;
	return a;
}

state_type operator*(state_type a, time_type b) {
	a.first *= b;
	a.second *= b;
	return a;
}

state_type operator*(time_type b, state_type a) {
	return a * b;
}

void harmonic_oscillator(const state_type& x, deriv_type& dxdt, time_type) {
	static auto constexpr gam = 0.1;

	dxdt.first = x.second;
	dxdt.second = -x.first - gam*x.second;
}

namespace bno = boost::numeric::odeint;
using stepper_type = bno::runge_kutta_dopri5<state_type, double, deriv_type, time_type, bno::vector_space_algebra>;

int main() {
	state_type x0{1.0, 0.0};
	
	// just to see if the operators work...
	x0 * 1.;
	2. * x0;
	x0 + x0;
	
	stepper_type stepper;
	time_type const dt = 0.005;
	for (time_type t = 0; t < 10; t += dt) {
		stepper.do_step(harmonic_oscillator, x0, t, dt);
		std::cout << t << '\t' << x0.first << '\t' << x0.second << '\n';
	}
	
	return EXIT_SUCCESS;
}
Ngôn ngữ chính
C++
Star
55
Fork
59
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của boostorg/odeint

Tất cả issue của boostorg/odeint

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.