Opened 4 years ago

Closed 4 years ago

#807 closed ожидаются исправления (задача сдана)

WW #14

Reported by: Alexander Morozov Owned by: Sokolov Viacheslav
Component: WW_exceptions Version: 1.0
Keywords: Cc:

Description


Change History (7)

comment:1 Changed 4 years ago by Sokolov Viacheslav

mkdir -p obj
g++ -O2 -Wall -Wextra -Werror -std=c++17 -Iinclude -c -MMD -o obj/matrix.o src/matrix.cpp
src/matrix.cpp: In member function ‘const int32_t& Matrix::at(int, int) const’:
src/matrix.cpp:11:17: error: catching polymorphic type ‘class std::exception’ by value [-Werror=catch-value=]

11 | } catch (std::exception) {

|

src/matrix.cpp: In member function ‘void Matrix::load(std::string)’:
src/matrix.cpp:58:17: error: catching polymorphic type ‘class std::exception’ by value [-Werror=catch-value=]

58 | } catch (std::exception) {

|

src/matrix.cpp:67:17: error: catching polymorphic type ‘class std::exception’ by value [-Werror=catch-value=]

67 | } catch (std::exception) {

|

cc1plus: all warnings being treated as errors
Makefile:17: recipe for target 'obj/matrix.o' failed
make: * [obj/matrix.o] Error 1

comment:2 Changed 4 years ago by Alexander Morozov

Заменил на передачу по константной ссылке. К сожалению, у меня ошибка не воспроизводилась.

comment:3 Changed 4 years ago by Sokolov Viacheslav

-rwxr-xr-x 1 nicesap nicesap 501 фев 24 19:46 Makefile*
Makefile зачем-то исполняемый

╰─>$ make
g++ -O2 -Wall -Wextra -Werror -std=c++17 -Iinclude -c -MMD -o obj/matrix.o src/matrix.cpp
g++ -O2 -Wall -Wextra -Werror -std=c++17 -Iinclude -c -MMD -o obj/main.o src/main.cpp
src/main.cpp: In function ‘int main()’:
src/main.cpp:33:21: error: implicitly-declared ‘Matrix& Matrix::operator=(const Matrix&)’ is deprecated [-Werror=deprecated-copy]

33 | regs[reg] = nw;

| ~

In file included from src/main.cpp:1:
include/matrix.h:22:3: note: because ‘Matrix’ has user-provided ‘Matrix::Matrix(const Matrix&)’

22 | Matrix(const Matrix &other) : _data(other._data) {}

| ~

src/main.cpp:42:52: error: implicitly-declared ‘Matrix& Matrix::operator=(const Matrix&)’ is deprecated [-Werror=deprecated-copy]

42 | regs[reg_to] = regs[reg_to] * regs[reg_from];

|

In file included from src/main.cpp:1:
include/matrix.h:22:3: note: because ‘Matrix’ has user-provided ‘Matrix::Matrix(const Matrix&)’

22 | Matrix(const Matrix &other) : _data(other._data) {}

| ~

src/main.cpp:54:19: error: catching polymorphic type ‘class std::bad_alloc’ by value [-Werror=catch-value=]

54 | } catch (std::bad_alloc) {

|

cc1plus: all warnings being treated as errors
Makefile:17: recipe for target 'obj/main.o' failed
make: * [obj/main.o] Error 1

рекомендую компилировать gcc (видимо, mac и clang)

comment:4 Changed 4 years ago by Alexander Morozov

У меня Windows и WSL, который по идее должен совпадать с Ubuntu... Я даже перед предыдущей посылкой зашел на сервер с убунту, и он тоже ничего не нашел. Перезагрузился в линукс на ноуте, он действительно выдал такие ошибки. Я решил, что это из-за отличий в версии GCC, на сервере 5.2, в WSL 7.4, а в линуксе на ноуте 9.2.

Закоммитил изменения, Makefile как обычно сделался исполняемым из-за того, что винда так сама ставит, забыл исправить.

comment:5 Changed 4 years ago by Alexander Morozov

Еще только что понял, что вывожу неправильное сообщение, если файл пуст или состоит из одного числа (unable to open file вместо incorrect file format). Добавил коммит, но особо не претендую на его проверку.

comment:6 Changed 4 years ago by Sokolov Viacheslav

Type: ожидается проверкаожидаются исправления

MatrixException?
final?

какая мотивация не разделять объявление и определение конструкторов?

26 Matrix
27 operator*(const Matrix &)const; strong guarantee, everything is const

выглядит не очень
кроме того, какая мотивация делать нессиметричными с точки зрения интерфейса + и *?

28 void load(std::string filename); basic guarantee

достаточно const std::string&

5 #include <iostream>

достаточно <iosfwd>

21 cin.exceptions(std::ios_base::failbit);
22 cout.exceptions(std::ios_base::failbit);
badbit? eof?

По Стандарту int может оказаться 16-битным, а размер матрицы может быть больше

60 try {
61 in >> n >> m;
62 _data = std::vector<std::vector<int32_t>>(n, std::vector<int32_t>(m));
63 for (auto &x : _data)
64 for (auto &y : x)
65 in >> y;
66 in.close();
67 } catch (const std::exception&) {
68 throw MatrixException?("LOAD: invalid file format.");
69 }

может вылететь std::bad_alloc, который будет неправильно обработан

48 return Matrix(result);
с текущих позиций лучше Matrix(std::move(result))

"Unable to allocate memory"
по условию просят еще точку в конце

comment:7 Changed 4 years ago by Sokolov Viacheslav

Resolution: задача сдана
Status: assignedclosed
Note: See TracTickets for help on using tickets.