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

Add an option to deal with warning of gcc #354

Merged
merged 3 commits into from
Aug 10, 2023
Merged

Conversation

llx07
Copy link
Contributor

@llx07 llx07 commented Jul 31, 2023

This will solve issue #214, #274.

If the exit code of the compiler is 0, and the STDERR is not empty, then we will consider the output of the STDERR is warning message, and the compilation will not be halted, the console will still be displayed with the message "Warnings while compiling".

The function will only be enabled if the new option "Zero Exit Code Is Warning" is enabled in the setting.

@llx07 llx07 changed the title Add a optional choice to deal with waring of gcc Add an option to deal with waring of gcc Jul 31, 2023
@llx07 llx07 changed the title Add an option to deal with waring of gcc Add an option to deal with warning of gcc Jul 31, 2023
@llx07
Copy link
Contributor Author

llx07 commented Jul 31, 2023

Here's an example of how this PR will work.

For example, we run the code below with compiler argument -Wall.

#include<bits/stdc++.h>
using namespace std;

int read(){
    int f=1,x=0;char c=getchar();
    while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
    while(isdigit(c)){x=x*10+c-'0';c=getchar();}
    return x*f;
}

int main(){
    int n=read();
    string s;
    cin>>s;
    for(auto c:s){
        cout<<(char)(c-'a'+'A');
    }
    return 0;
}

Before:
image
The compilation will be halted, but as a cp contestant, what we want is to read the warning while testing the testcase.

Now:
image
Now it can successfully display the warning and test the testcases at the same time.

@llx07
Copy link
Contributor Author

llx07 commented Jul 31, 2023

P.S.
The condition in the if-statement in src/compiler.ts might seem a little complicated, this is because I want cph work exactly the same as before (If the new option is not enabled).

I'm wondering if it is possible to judge whether the compilation is success only by the exitcode. I don't use other language besides C++, but in my test, it's ok to do this in g++.

i.e. Can the code be rewritten to the following?

        compiler.on('exit', (exitcode) => {
-            if (exitcode === 1 || error !== '') {
+            if (exitcode === 1) {  
                ocWrite('Errors while compiling:\n' + error);
                ocShow();
                console.error('Compilation failed');
                resolve(false);
                getJudgeViewProvider().extensionToJudgeViewMessage({
                    command: 'compiling-stop',
                });
                getJudgeViewProvider().extensionToJudgeViewMessage({
                    command: 'not-running',
                });
                return;
            }
+            if (error !== '') {
+                ocWrite('Warnings while compiling:\n' + error);
+                ocShow();
+            }
            console.log('Compilation passed');
            getJudgeViewProvider().extensionToJudgeViewMessage({
                command: 'compiling-stop',
            });
            resolve(true);
            return;
        });
    });
    return result;
};

@tesla59 tesla59 self-requested a review August 6, 2023 06:07
@hieupham1103
Copy link

Screenshot 2023-08-07 at 20 17 14

I have added -Wall to compiler argument but it still exists
My code here

#include<bits/stdc++.h>
#define ii pair <int,int>
#define fi first
#define se second
#define int long long
#define double long double
#define endl '\n'
#define all(x) x.begin(), x.end()
using namespace std;

const int maxN = 2e5 + 10;

int a[maxN];
unordered_map <int,int> cnt[12];

signed main(){
    //freopen("input.INP", "r", stdin);
    //freopen("output.OUT", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        cnt[(int)log10(a[i]) + 1][a[i] % k]++;
        // cout << (int)log10(a[i]) + 1 << ' ' << a[i] % k << endl;
    }
    int res = 0;
    for (int i = 1; i <= n; i++){
        // cout << "*" << i << endl;
        for (int l = 1, t = 10; l <= 10; l++){
            int rem = (k - (a[i] * t) % k + k) % k;
            int te = cnt[l][rem];
            if (l == (int)log10(a[i]) + 1 and a[i] % k == rem){
                te -= 1;
            }
            // cout << a[i] * t << ' ' << (a[i] * t) % k  << ' ' << rem << endl;
            // cout << l << ' ' << te << endl;
            res += te;
            t *= 10;
            t %= k;
        }
        // cout << endl;
    }

    cout << res << endl;
    return 0;
}
/*
1000000000
10000000000
*/

@tesla59
Copy link
Collaborator

tesla59 commented Aug 10, 2023

STDERR is not empty

Can u please explain your scenario?

@tesla59
Copy link
Collaborator

tesla59 commented Aug 10, 2023

P.S. The condition in the if-statement in src/compiler.ts might seem a little complicated, this is because I want cph work exactly the same as before (If the new option is not enabled).

I'm wondering if it is possible to judge whether the compilation is success only by the exitcode. I don't use other language besides C++, but in my test, it's ok to do this in g++.

i.e. Can the code be rewritten to the following?

        compiler.on('exit', (exitcode) => {
-            if (exitcode === 1 || error !== '') {
+            if (exitcode === 1) {  
                ocWrite('Errors while compiling:\n' + error);
                ocShow();
                console.error('Compilation failed');
                resolve(false);
                getJudgeViewProvider().extensionToJudgeViewMessage({
                    command: 'compiling-stop',
                });
                getJudgeViewProvider().extensionToJudgeViewMessage({
                    command: 'not-running',
                });
                return;
            }
+            if (error !== '') {
+                ocWrite('Warnings while compiling:\n' + error);
+                ocShow();
+            }
            console.log('Compilation passed');
            getJudgeViewProvider().extensionToJudgeViewMessage({
                command: 'compiling-stop',
            });
            resolve(true);
            return;
        });
    });
    return result;
};

i think we should keep checking the error and the exit code

@tesla59 tesla59 merged commit 7f2d272 into agrawal-d:main Aug 10, 2023
4 checks passed
@llx07
Copy link
Contributor Author

llx07 commented Aug 10, 2023

STDERR is not empty

Can u please explain your scenario?

The scenario is explained in the previous comment.

When you enable -Wall in g++, then compiler may give warning(s) in STDERR, but the compliation is still success, and the exitcode is 0.

@tesla59
Copy link
Collaborator

tesla59 commented Aug 10, 2023

STDERR is not empty

Can u please explain your scenario?

The scenario is explained in the previous comment.

When you enable -Wall in g++, then compiler may give warning(s) in STDERR, but the compliation is still success, and the exitcode is 0.

Hi @linlexiao0 . sorry i wrongly tagged u. I meant to mention @hieupham1103 on their scenario

@KLYleo
Copy link

KLYleo commented Aug 11, 2023

how to add this to my cph in vscode

@llx07
Copy link
Contributor Author

llx07 commented Aug 11, 2023

how to add this to my cph in vscode

@KLYleo
The feature haven't been published yet, but you can use my prerelease here.

@KLYleo
Copy link

KLYleo commented Aug 11, 2023

how to add this to my cph in vscode

@KLYleo 该功能尚未发布,但您可以在此处使用我的预发布。

ok thx

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

Successfully merging this pull request may close these issues.

4 participants