I have a weird error when I compile my project on MSVC.
I am using Microsoft Visual Studio 15 2017 and I compile in c++17 (MSVC version 15.6.85.37198)
The code compiles on Clang and G++ but it gives me an error on MSVC.
I managed to reduce the code causing the error to the following snippet :
#include <cstddef>
struct Point {
double x;
double y;
double z;
};
template<class... Ps>
void doSomething() {
offsetof(Point, x);
}
int main() {
doSomething();
}
It gives me the following error :
main.cpp(10): fatal error C1903: unable to recover from previous error(s); stopping compilation [buildexample.vcxproj]
I was a bit puzzled at first since it was the only error and it took me quite some time before I could identify that the problem came from offsetof.
The problem come from using the offsetof macro inside a templated function that takes a parameter pack in.
I do not think this code is doing anything illegal or is using undefined behavior. So, is the problem on my end or is it a bug in the compiler ?
Thanks
У меня странная ошибка, когда я компилирую свой проект в MSVC.
Я использую Microsoft Visual Studio 15 2017 и компилирую в c ++ 17 (версия MSVC 15.6.85.37198)
Код компилируется на Clang и G ++, но на MSVC выдает ошибку.
Мне удалось уменьшить код, вызывающий ошибку, до следующего фрагмента:
#include <cstddef>
struct Point {
double x;
double y;
double z;
};
template<class... Ps>
void doSomething() {
offsetof(Point, x);
}
int main() {
doSomething();
}
Это дает мне следующую ошибку:
main.cpp(10): fatal error C1903: unable to recover from previous error(s); stopping compilation [buildexample.vcxproj]
Сначала я был немного озадачен, так как это была единственная ошибка, и мне потребовалось довольно много времени, чтобы понять, что проблема возникла из-за offsetof.
Проблема исходит от использования offsetof макрос внутри шаблонной функции, которая принимает пакет параметров.
Я не думаю, что этот код делает что-то незаконное или использует неопределенное поведение. Итак, проблема с моей стороны или это ошибка в компиляторе?
Спасибо
2
Решение
поскольку Point это стандартный тип макета, использование offsetof(Point, x) четко определен.
Тот факт, что MSVC17 не может скомпилировать ваш минимальный пример, безусловно, является ошибкой из-за его неспособности полностью поддерживать пакеты параметров шаблона.
4
Другие решения
Других решений пока нет …
Message Text
unable to recover from previous error(s); stopping compilation
Circumstances
The compiler typically attempts some sort of continuation after an error, and
it is not the policy of these notes ever to criticise (or even bring to attention)
any quirks in the compiler’s sometimes valiant attempts at such continuation. In
some cases, the compiler declines to try continuing, even though the error would
ideally not be fatal. The visible result is fatal error C1903. It may be that something
unusual is noticed about the circumstances, such that the error is ordinarily not
fatal but in these circumstances is too difficult and is instead declared fatal.
It may just be that the error is always fatal in practice because although the compiler’s
writers have not defined a fatal error number for it, and might not want to, neither
have they yet got round to writing code for any continuation.
One error for which the front-end C++ compiler presently provides no continuation
in any circumstances is C2687. To generate this error, ignore everything that the
product documentation says about it, and instead attempt an out-of-line definition
of a class that is nested in a template class, e.g.,
template <typename T> class Test
{
class Nested;
};
template <typename T> class Test <int> :: Nested // C2687 and C1903
{
};
One case is known where fatal error C1903 is the one and only message given to
the user, who may then puzzle over the “previous error(s)” that are never described.
To observe, compile the one-line source file:
#import <rubbish> ptrsize (0)
CPU Exceptions
Fatal error C1903 can also occur in response to a CPU exception. If there has
already been an error during compilation, no matter how long before and how well
recovered, then a CPU exception that would ordinarily be reported as an internal
compiler error C1001, specifically in the case that version
13.00.9466 attributes to
compiler file 'msc1.cpp', line 2844
is instead reported as fatal error C1903. The thinking is presumably that the
compiler is continuing from an error and the CPU exception is an artifact of the
continuation having been too bold. Though the exception is more or less by definition
a coding error in the compiler, it may reasonably be forgiven and should be regarded
as an internal compiler error only if it persists after the other errors have been
fixed.
For example, compile the following with the /Zc:wchar_t
option and without /Yu.
1; // C2059 #if _WCHAR_T_DEFINED // C1903 #endif
The second line (indeed, any evaluation of the built-in macro
_WCHAR_T_DEFINED)
is known to trigger a coding error in the compiler. The first line is added just
to contrive a previous error. Delete the first line, i.e., deal with the contrived
error, to reveal that the C1903 is really a C1001.
Hello
I try to compile the code but it show me this message
Can any one help me,please..?
C:/PROGRA~1/SIDEEF~1/HOUDIN~1.557/toolkit/includeUT/UT_PageArray.h(751): error C2143: syntax error: missing ';' before '&'
C:/PROGRA~1/SIDEEF~1/HOUDIN~1.557/toolkit/includeUT/UT_PageArray.h(726): note: see reference to function template instantiation 'void UT_PageArray<DATA_T,0x03,true,false,0x0a,GA_Offset>::opVector<1,T,0x03,false>(IDX_T,const UT_FixedVector<T,0x03,false> &)' being compiled
with
[
DATA_T=float,
T=fpreal32,
IDX_T=GA_Offset
]
C:/PROGRA~1/SIDEEF~1/HOUDIN~1.557/toolkit/includeUT/UT_PageArray.h(726): note: see reference to function template instantiation 'void UT_PageArray<DATA_T,0x03,true,false,0x0a,GA_Offset>::opVector<1,T,0x03,false>(IDX_T,const UT_FixedVector<T,0x03,false> &)' being compiled
with
[
DATA_T=float,
T=fpreal32,
IDX_T=GA_Offset
]
c:program filesside effects softwarehoudini 16.0.557toolkitincludegaGA_Handle.h(396): note: see reference to function template instantiation 'void UT_PageArray<DATA_T,0x03,true,false,0x0a,GA_Offset>::addVector<T,0x03,false>(IDX_T,const UT_FixedVector<T,0x03,false> &)' being compiled
with
[
DATA_T=float,
T=fpreal32,
IDX_T=GA_Offset
]
c:program filesside effects softwarehoudini 16.0.557toolkitincludegaGA_Handle.h(396): note: see reference to function template instantiation 'void UT_PageArray<DATA_T,0x03,true,false,0x0a,GA_Offset>::addVector<T,0x03,false>(IDX_T,const UT_FixedVector<T,0x03,false> &)' being compiled
with
[
DATA_T=float,
T=fpreal32,
IDX_T=GA_Offset
]
c:program filesside effects softwarehoudini 16.0.557toolkitincludegaGA_Handle.h(390): note: while compiling class template member function 'void GA_RWHandleT<UT_Vector3F,void>::add(GA_Offset,const T &) const'
with
[
T=UT_Vector3F
]
c:program filesside effects softwarehoudini 16.0.557toolkitincludegaGA_Detail.h(228): note: see reference to function template instantiation 'void GA_RWHandleT<UT_Vector3F,void>::add(GA_Offset,const T &) const' being compiled
with
[
T=UT_Vector3F
]
c:program filesside effects softwarehoudini 16.0.557toolkitincludegaGA_Detail.h(2333): note: see reference to class template instantiation 'GA_RWHandleT<UT_Vector3F,void>' being compiled
C:/PROGRA~1/SIDEEF~1/HOUDIN~1.557/toolkit/includeUT/UT_PageArray.h(751): error C2461: 'UT_PageArray<DATA_T,0x03,true,false,0x0a,GA_Offset>::opVector::<lambda_67d628b5d159f3bfebe255aa5eaa59b6>': constructor syntax missing formal parameters
with
[
DATA_T=float
]
C:/PROGRA~1/SIDEEF~1/HOUDIN~1.557/toolkit/includeUT/UT_PageArray.h(751): error C2238: unexpected token(s) preceding ';'
C:/PROGRA~1/SIDEEF~1/HOUDIN~1.557/toolkit/includeUT/UT_PageArray.h(751): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:/PROGRA~1/SIDEEF~1/HOUDIN~1.557/toolkit/includeUT/UT_PageArray.h(751): error C2143: syntax error: missing ',' before '&'
C:/PROGRA~1/SIDEEF~1/HOUDIN~1.557/toolkit/includeUT/UT_PageArray.h(751): error C2610: 'UT_PageArray<DATA_T,0x03,true,false,0x0a,GA_Offset>::opVector::<lambda_67d628b5d159f3bfebe255aa5eaa59b6>::<lambda_67d628b5d159f3bfebe255aa5eaa59b6>(const int)': is not a special member function which can be defaulted
with
[
DATA_T=float
]
C:/PROGRA~1/SIDEEF~1/HOUDIN~1.557/toolkit/includeUT/UT_PageArray.h(751): error C2061: syntax error: identifier '<lambda_67d628b5d159f3bfebe255aa5eaa59b6>'
C:/PROGRA~1/SIDEEF~1/HOUDIN~1.557/toolkit/includeUT/UT_PageArray.h(751): error C2535: 'UT_PageArray<DATA_T,0x03,true,false,0x0a,GA_Offset>::opVector::<lambda_67d628b5d159f3bfebe255aa5eaa59b6>::<lambda_67d628b5d159f3bfebe255aa5eaa59b6>(void)': member function already defined or declared
with
[
DATA_T=float
]
C:/PROGRA~1/SIDEEF~1/HOUDIN~1.557/toolkit/includeUT/UT_PageArray.h(751): note: see declaration of 'UT_PageArray<DATA_T,0x03,true,false,0x0a,GA_Offset>::opVector::<lambda_67d628b5d159f3bfebe255aa5eaa59b6>::<lambda_67d628b5d159f3bfebe255aa5eaa59b6>'
with
[
DATA_T=float
]
C:/PROGRA~1/SIDEEF~1/HOUDIN~1.557/toolkit/includeUT/UT_PageArray.h(749): error C2228: left of '.this' must have class/struct/union
C:/PROGRA~1/SIDEEF~1/HOUDIN~1.557/toolkit/includeUT/UT_PageArray.h(751): fatal error C1903: unable to recover from previous error(s); stopping compilation
for Houdini FX 16.0.557
Thank you in advanced..
Делаю интерфейс для работы с БД. Проект Windows Forms.
Скачаны исходники с оф. сайта sqlite.org/download.html (sqlite-amalgamation-3080301.zip).
Добавляю в проект заголовочные файлы и файлы исходного кода (у них указываю, что компилировать надо как код C++ (/TP)) — выдает огромную кучу ошибок в исходниках, и в конце:
fatal error C1903: не удается восстановить после предыдущих ошибок; остановка компиляции
Проблема в добавлении С-файлов к Сpp-файлам?
Какие могут быть причины/альтернативные решения? Я что-то упускаю? Третий день ничего от гугла не добиться.
-
Вопрос заданболее трёх лет назад
-
3812 просмотров
Пригласить эксперта
Может наоборот надо указать что нужно компилировать как код C, а не C++ (Compile as C Code (/TC)). Еще думаю нужно отключить у sqlite.c использование Precompiled Headers (Not Using Precompiled Headers)
-
Показать ещё
Загружается…
28 янв. 2023, в 22:48
500 руб./за проект
28 янв. 2023, в 20:58
30000 руб./за проект
28 янв. 2023, в 20:46
50000 руб./за проект
Минуточку внимания
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
main.cpp #include <string> #include <conio.h> #include "book.h" #include "vse.h" #include <iostream> using namespace std; book *fill(book *books, int); int main() { int button=0; char author[40]; char title [40]; char vidav[40]; int old_year,n; setlocale(0, "rus"); std::cout <<"Vvedite kolichestvo knig " << std::endl; std::cin>> n; vse mas(n):m_n; fill(books,n); while(button!=4) { std::cout<< "Выберите опцию и нажмите соответсвующую кнопку"<<std::endl; std::cout << "1.Вывести список книг заданого автора"<< std::endl; std::cout << "2.Вывести список книг заданого видавництва" <<std::endl; std::cout <<"3. Вывести список книг виданого пізніше заданого року" << std::endl; std::cout <<"4. Выход из программы" << std::endl; std::cin >> button; switch(button) { case 1: std::cout <<"Введите автора" << std::endl; std::cin >>author; mas->vse::find1(books, author, n); break; case 2: std::cout << "Введите издательство:"<<std::endl; std::cin >>vidav; mas->vse::find2(books,vidav,n); break; case 3: std::cout <<"Введите год:" << std::endl; std::cin >> old_year; mas->vse::find3(books,old_year,n); break; case 4: return 0; break; } } delete [] books; delete mas; getch(); } book *fill(book *books, int n) { std::string author,vidav,title; int old_year; for(int i=0; i<n; i++) { std::cout << "nVvediten"; std::cin.get(); std::cout << "Avtor " << i+1 <<": " << std::endl; std::getline(std::cin,author); books[i].set_author(author); std::cout <<"vidav " <<i+1 << ": " << std::endl; std::cin>> vidav; books[i].set_vidav(vidav); std::cout << "year " <<i+1 <<": " << std::endl; std::cin >> old_year; books[i].set_old_year(old_year); std::cout << "Nazva knigi " <<i+1 << ": " << std::endl; std::cin >> title; books[i].set_title(title); } return books; } book.h #include <string> #include <iostream> using namespace std; class book { string author,title,vidav; int old_year ; public: book (string n,string t,string v, int y,int p):author(n),title(t),vidav(v),old_year(y) {}; string get_author(){return author;} string get_title(){return title;} string get_vidav(){return vidav;} int get_old_year(){return old_year;} void set_old_year (int y) { old_year = y;} void set_author (string n) { author=n;} void set_title (string t) { title = t;} void set_vidav (string v) { vidav = v;} }; book.cpp #include <string> #include <iostream> #include "book.h" //------------------------------------------------ void book::set_old_year(int p_old_year)// { old_year = p_old_year; } int book::get_old_year() { return old_year; } void book::set_author(std::string p_author) { author = p_author; } std::string book::get_author() { return author; } void book::set_title(std::string p_title) { title = p_title; } std::string book::get_title() { return title; } void book::set_vidav( std::string p_vidav) { vidav = p_vidav; } std::string book::get_vidav() { return vidav;} vse.h #pragma once #include <string> #include "book.h" class vse { private: int m_n; public: vse(int n ):m_n(n) { book *books=new book(m_n); }; ~vse(){}; void dump(book); void find1(book*,char*,int n); void find2(book*,char* ,int n); void find3(book*,int year,int n); }; vse.cpp #include <iostream> #include <string> #include "book.h" #include "vse.h" //------------------------------------------------ // метод вывода на экран элемента массива void vse::dump(book objs) { std::cout << "Author: "<<objs.get_author() << std::endl << "Vidav: " <<objs.get_vidav() << std::endl << "Year: " <<objs.get_old_year() << std::endl << "Nazva" <<objs.get_title() << std::endl; } //------------------------------------------------ // вывести автора void vse::find1(book* books, char author[40], int n) { for ( int i=0;i<n;i++) { if (books[i].get_author() == author) this->dump(books[i]); } } //вивести список книг надрукованих пізніше заданого року void vse::find3(book* books,int n,int old_year) { for (int i=0;i<n;i++) { if ((books[i].get_old_year() >= old_year)) this->dump(books[i]); } } //---------------------------------------------------- //список книг заданого видавництва void vse::find2(book* books, char vidav[40], int n) { for ( int i=0;i<n;i++) { if (books[i].get_vidav() == vidav) this->dump(books[i]); } } |